Replies: 2 comments 5 replies
-
#3633 is a checkpoint PR, and things seem to work well for non-timeout perpetual loops that get cancelled by a stop-signal. I believe mio has timeouts built into the system as well: might be interesting to investigate that? As for option 5: that's a no-go for me. unsafe, and too much platform dependant behavior. I think it's also important to clean up threads when needed, and not rely on the process stopping. I think |
Beta Was this translation helpful? Give feedback.
-
What's the use case of this timeout ? For the writing and reading on network you can use the For global timeout any solution could work I personally like the crossbeam with timeout |
Beta Was this translation helpful? Give feedback.
-
For the conversion of async bootstrap to sync we need to convert this tokio timeout who is async.
I have tested a lot of stuff and here is a summary :
after()
If you have any suggestion or know another way to do it i will be happy to test it.
1 : crossbeam channel with
after()
:https://docs.rs/crossbeam-channel/latest/crossbeam_channel/fn.after.html#examples
Sounds good but no really. if i create a loop in the spawned thread and make the main thread live :
The function is ended instantly when the timeout is reached but the async task continue to leave. In fact this is what we want when we spawn thread.
If we want to stop the spawned thread we want another solution.
2 : thread + channel with drop(handle)
Same result as the first version
3 : async_std cancel
https://docs.rs/async-std/latest/async_std/task/struct.JoinHandle.html#method.cancel
Main thread is block by handle.cancel()
4 : future abort()
https://docs.rs/futures/latest/futures/future/struct.Abortable.html#method.new
Same result as 1 && 2
5 : Unsafe kill thread
https://crates.io/crates/stop-thread
https://github.com/sollyucko/stop-thread
Their is one function for windows and one other for unix system.
With this unsafe crate the thread was instantly killed without waiting for the completion of the execution..
Beta Was this translation helpful? Give feedback.
All reactions