Xudong-Huang/may

How to cancel a coroutine?

Hirrolot opened this issue · 4 comments

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?

I found the Coroutine::cancel() unsafe function, is it? Also the whole Coroutine structure is undocumented, it's quite strange.

Also is there an approach for exiting a whole scope of coroutines?

Yes, you can use the cancel method when you have a coroutine handle. There is no API to cancel a whole scoped coroutines.

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.