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

Add Channel#trySend #2768

Merged
merged 11 commits into from
Mar 29, 2022
Merged

Conversation

armanbilge
Copy link
Member

Opening to get feedback on the idea, which is to provide a "view" to a Channel as a QueueSink. This allows APIs to use the QueueSink interface and for a Channel to be plugged in as an implementation detail.

To adapt the Channel interface for QueueSink I added:

  1. an implementation of trySend (analog to tryOffer), which is a non-blocking version of send.
  2. a Channel.ClosedException which is thrown when encountering a Channel.Closed.

Thanks for your consideration.

/** Provides an interface to the channel as a [[QueueSink]].
* Offering elements to a closed queue will raise a [[Channel.ClosedException]].
*/
def asQueueSink: QueueSink[F, A]
Copy link
Member Author

Choose a reason for hiding this comment

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

Alternatively, Channel itself could extend QueueSink?

@armanbilge armanbilge marked this pull request as ready for review January 2, 2022 01:53
@armanbilge
Copy link
Member Author

Some feedback from @SystemFw

I'm 50/50 about it
Channel has a few semantic aspects that I think you ought to keep in mind when using it: graceful closure, single consumer, chunking by default (most cases of a queue consumed by a stream fall into this), so I'm not too sure about hiding those

I think those are fair points. WDYT about reducing the scope of this PR to just the trySend method? Then a QueueSInk adapter can be a user-land thing, if at all.

@armanbilge armanbilge changed the title Provide QueueSink "view" to a Channel Add Channel#trySend Feb 19, 2022
@armanbilge
Copy link
Member Author

Ok, I came to appreciate Fabio's point, and I changed my mind about the QueueSink thing. I'd still like the trySend op actually, so I kept that.

@mpilquist mpilquist merged commit f504097 into typelevel:main Mar 29, 2022
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.

2 participants