Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Channels implementation with new listeners #23

Merged
merged 21 commits into from
Dec 10, 2023

Conversation

natsukagami
Copy link
Contributor

@natsukagami natsukagami commented Dec 8, 2023

Depends on #21 and #22.

Channel stuff

  • New implementation for sync and bounded channels, based on lockBoth.
  • Remove suspendSupport requirement from channel.
  • New channel kind: unbounded channels, with .sendImmediately non-suspending.
  • ChannelMultiplexer changes a bit: there is now a blocking/suspending start() method instead of spawning a background working.

Stuff based on channels

  • Future Collectors: Seq[Future[T]] => ReadableChannel[Future[T]], with values arriving as they are completed.
  • Implement collector-based future collection extensions: Seq[Future[T]] has awaitAll(OrCancel) and altAll(WithCancel)

Other misc goodies

  • Add shorthand .await syntax to sources.
  • Add Source.values to quickly create a new source based on a list of values.

@natsukagami natsukagami force-pushed the explicit-channels-prelim branch from ede4896 to d8f457c Compare December 8, 2023 18:41
@natsukagami natsukagami force-pushed the explicit-channels-prelim branch from d8f457c to 8f41bc3 Compare December 8, 2023 18:54
@natsukagami natsukagami marked this pull request as ready for review December 8, 2023 18:56
Copy link
Contributor

@m8nmueller m8nmueller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The abstraction of channels is great!!

I also changed some things in place, have a look.

shared/src/main/scala/async/channels.scala Outdated Show resolved Hide resolved
shared/src/main/scala/async/channels.scala Outdated Show resolved Hide resolved
}
end UnboundedChannel

object Channel:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be possible to extract all listener completion outside of the synchronized parts to increase concurrency. But it is a tedious work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is possible (in fact it should be possible to implement completely lock-free channels) but not right now

subscribersCopy = subscribers.toList
for (s <- subscribersCopy) s.send(Failure(ChannelClosedException()))
shouldTerminate = true
case Right(Message.Refresh) => ()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this exist? And if it is only quit left, then I guess the info channel is not needed anymore. You can implement the quit using a (classical) Promise instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refresh is needed as like a continue for the while loop. Happens when we made a change to the subscriber/publisher list.

@m8nmueller m8nmueller force-pushed the explicit-channels-prelim branch from b20f227 to 3fffabc Compare December 10, 2023 14:39
ChannelMultiplexer is very dependent on subscribing order, and should be
either set up correctly or used by subscribers that don't really care
about past events.
... to make it consistent with ChannelMultiplexer.
Overall `start` sounds more like a background running thing w.r.t
threads.
Copy link
Contributor

@m8nmueller m8nmueller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nicely done with map. LGTM.

@natsukagami natsukagami merged commit 86159db into lampepfl:main Dec 10, 2023
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants