tokahuke / yaque

Yaque is yet another disk-backed persistent queue for Rust.
Other
79 stars 11 forks source link

Is there a try_recv like function? #9

Closed vedantroy closed 3 years ago

vedantroy commented 3 years ago

Is there a function that will try receiving, and if the queue has no data, will return None?

It seems like I can manually replicate this now by using recv_timeout with a very small timeout, but wondering if there was a more idiomatic way?

tokahuke commented 3 years ago

@vedantroy nope, but I was waiting for somebody to ask for that. As I said, I have been having some spare time today to implement stuff in yaque. I will create a pull request for that.

tokahuke commented 3 years ago

We are in luck! We can use the futures::FutureExt::now_or_never utility to achieve this behavior, without the need to refactor all the code.

tokahuke commented 3 years ago

PR #10 . Some considerations:

I think this is not the most efficient way of implementing try_recv, since it uses the async functions under the hood and thus does some stuff which is not useful for only one poll. However, it is not a horrible idea and it is Easy to Explain©. Let's worry about benchmarks in a future version.

tokahuke commented 3 years ago

Try recv implemented and available in version v0.6.0