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

Mechanism for detecting when sending to a closed channel #79

Open
sandhu opened this issue Nov 15, 2017 · 0 comments
Open

Mechanism for detecting when sending to a closed channel #79

sandhu opened this issue Nov 15, 2017 · 0 comments

Comments

@sandhu
Copy link

sandhu commented Nov 15, 2017

There is currently no way to detect when you're snding to a closed channel.

In core.async, a nil is returned if the channel being "put" to is closed and a non-nil value is returned to indicate that the channel was still open and the "put" succeeded.

It would be useful to have snd behave the same way.

The use case that I have is one where a producer returns a buffered blocking channel that will contain a large stream of data. The wrinkle is that it is very expensive to produce the entire sequence of data and the client will not need to consume the entire sequence.

The producer only produces the size of the buffer in the channel and blocks until the client needs more.

In my core.async implementation, the consumer signals that it is no longer interested in the data by closing the channel. The producer detects this and stops producing. This pattern works really well and I'm using it in a variety of scenarios.

I can't implement the same pattern in pulsar, because as soon as the consumer closes the channel, the producer unblocks and ends up producing the entire sequence since there is no way to detect that the channel has been closed.

closed? returns false since there are items already in the buffer of the channel and those will never be consumed since the consumer is "done".

I realize this is a pretty fundamental change, but I'd appreciate you looking into it and considering it.

Thank you.

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

No branches or pull requests

1 participant