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

should the channel have a non-blocking consume. #231

Open
dadkins789 opened this issue Sep 22, 2020 · 2 comments
Open

should the channel have a non-blocking consume. #231

dadkins789 opened this issue Sep 22, 2020 · 2 comments

Comments

@dadkins789
Copy link

I need a non-blocking channel so I modified tryConsumeOne() to return early on either an empty queue or a closed condition, rather a blocking until a closed condition or an item in the queue. I added an isClosed() property to check if a tryConsumeOne() returns false and I need to check for a channel closed state. Are there other ways to do non-blocking channel reads that I am missing? Also, empty() also blocks on the same conditions as tryConsumeOne().

@s-ludwig
Copy link
Member

We could add a poll() method that behaves like your modified version of tryConsumeOne and possibly let it return an enum instead of bool, so that it is possible to distinguish between an closed and empty channel and an open channel with an empty buffer. Doing it separately is always prone to introducing race-conditions.

@dadkins789
Copy link
Author

Oops, I see an example of the intended use of tryConsumeOne in listDirectory core/file.d. My implementation of tryConsumeOne will definitely break it. You are using close to terminate a blocking call when no more producer data is forthcoming. I agree a separate function that performs the non-blocking makes sense to prevent breakage of the existing behavior. put is also blocking on a full queue so for symmetry a non blocking put might also be useful. Let me know if you decide to do it. I'll fix my patched implementation to add a poll and revert tryConsumeOne. Thanks for looking at it.

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

2 participants