Closed jBernavaPrah closed 6 months ago
hi,
it is quite a long time I did not touch this library :)
ad 1) I don't think you can really put async function into callback, because this function is actually passed into underlying C code. Callbacks should ideally execute quickly in non blocking way. If you still need to execute async code try using tokio::spawn
or tokio::task::spawn_blocking
. Spinning up whole tokio in callback as you do is highly ineffective. You can also try using sync channels and in callback simply forward/send message into channel. Receiver can then process tasks again by tokio:spawn
or similar technique.
ad 2) example must use sleep to prevent main thread from terminating. this is just simple example. In reality you would have som long running process like web server that will be processing this in separate tokio tasks.
To get deeper understanding of rust async programming I suggest going thoroughly through following tokio tutorial: https://tokio.rs/tokio/tutorial
good luck with Rust endevours :)
Hi,
First of all, thanks for this package!
I'm still learning rust, so sorry if they are silly questions.
Currently, I achieve it using a new Tokio runtime:
There is a better way to do it?
Could a loop with sleep do it?
Thanks for your time!