rster2002 / ed-journals

Work in progress journal parsing and utilities for Elite Dangerous written in Rust.
https://crates.io/crates/ed-journals
MIT License
3 stars 4 forks source link

Blocking readers: channel-like API? #51

Open plule opened 4 months ago

plule commented 4 months ago

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:

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 commented 4 months ago

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 commented 4 months ago

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

rster2002 commented 1 month ago

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