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

Blocking readers: channel-like API? #51

Open
plule opened this issue May 26, 2024 · 3 comments
Open

Blocking readers: channel-like API? #51

plule opened this issue May 26, 2024 · 3 comments
Milestone

Comments

@plule
Copy link

plule commented May 26, 2024

When working without an async runtime it can be a bit awkward to manage the blocking calls of the live readers. I think that the standard library channel Receiver do it really well:

  • .iter() provides the blocking API, exactly like the current live readers
  • .try_iter() provides an iterator that is non blocking and ends as soon as there is no more events

And the great thing is that you can use both as needed. As a result, this creates easy constructions to do things like watching just new events:

let _ = receiver.try_iter().last(); // flush the events that were sent before
for ev in receiver.iter() { /* do stuff with new events */}

They also provide the method recv_timeout() which is super helpful.

@rster2002
Copy link
Owner

rster2002 commented May 26, 2024

Have you looked at the non-live variants of the readers? It allows you to perform reads without blocking and just returns an option. Otherwise I would have to look into this, but that would probably be after 0.5 release.

@plule
Copy link
Author

plule commented May 26, 2024

I'll take a look and give a shot to implement it from the non-live one

@rster2002 rster2002 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 7, 2024
@rster2002
Copy link
Owner

Might go back on this, at least providing something like 'try_next' or something like that. Reopening to keep it in sight.

@rster2002 rster2002 reopened this Aug 14, 2024
@rster2002 rster2002 added this to the Backlog milestone Aug 14, 2024
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