How to cancel a coroutine?
Hirrolot opened this issue · 4 comments
Hirrolot commented
It seems that this crate provides the ability to cancel coroutines, but I can't resolve how to do it. What is the general syntax for coroutine cancellation?
Hirrolot commented
I found the Coroutine::cancel()
unsafe function, is it? Also the whole Coroutine
structure is undocumented, it's quite strange.
Hirrolot commented
Also is there an approach for exiting a whole scope of coroutines?
Xudong-Huang commented
Yes, you can use the cancel
method when you have a coroutine handle. There is no API to cancel a whole scoped coroutines.
Xudong-Huang commented
you could use the select!
macro with a timeout branch. if the timeout happens, it will cancel all the other branches. and in the select macro, you can use local ref too.