dioxus icon indicating copy to clipboard operation
dioxus copied to clipboard

Add `try_recv` to `Eval`

Open Sitin opened this issue 9 months ago • 2 comments

Feature Request

Add a "non-blocking" try_recv metod to Eval struct returned by document::eval.

Reasoning

This method can be useful when we want both send and receive from Eval.

Sitin avatar Mar 26 '25 06:03 Sitin

The try_next method returns a future, it doesn't block the thread. If you need to do other work at the same time, you could use join or if you want to check if the future is ready without waiting, you can use now_or_never:

let res: Option<Result<String, _>> = eval.recv().now_or_never();

Would the try_recv you propose in this issue act any differently from eval.recv().now_or_never()?

ealmloff avatar Mar 26 '25 13:03 ealmloff

For two reasons. First, try_* is a general pattern found all over std and community libraries. This would create a predictable API. Second, Dioxus already uses evaluator.try_write in recv(). Why should we wrap it into a future for those library users who don't need this?

Sitin avatar Mar 26 '25 19:03 Sitin