lemunozm / message-io

Fast and easy-to-use event-driven network library.
Apache License 2.0
1.11k stars 74 forks source link

Request for try_receive() or some variant of non-blocking receive for EventQueue #46

Closed RobDavenport closed 3 years ago

RobDavenport commented 3 years ago

Awesome create! I'm really impressed with the ergonomics and flexibility of this so far!

It would be nice to have access to a non-blocking receive function inside of EventQueue.

Reasons

Current solution: Calling receive_timeout with zero duration, such as: events.receive_timeout(Duration::from_nanos(0))

I considered making a PR for this myself (and probably will if it doesn't get added by anyone else), unless it's deemed unnecessary or pointless compared to the current solution. The code looked a little more involved than I thought though!

lemunozm commented 3 years ago

Thanks @RobDavenport!! I am glad that you like message-io :D

I' am not sure about the delay events.receive_timeout(Duration::from_nanos(0)) generates, I think that it is minimal, but it's true that you stop the process into an OS select and maybe sometimes it produces some delay by the OS to recover the process.

Anyway, I like the idea of a PR! I think that something like events.try_receive() (which would return an option) is simpler and more readable for your use case than the current solution.

The crossbeam channel has already a try_recv function, so I think that the solution would consist into call try_recv to the three internal receivers that EventQueue has.

If you want to contribute, it would be great! Thanks!