Xudong-Huang / may

rust stackful coroutine library
Apache License 2.0
1.93k stars 80 forks source link

Structured concurrency support #78

Open carlopires opened 4 years ago

carlopires commented 4 years ago

Does it support structured concurrency in some way?

https://en.wikipedia.org/wiki/Structured_concurrency

Xudong-Huang commented 4 years ago

There are several ways to control and wait the sub coroutines

  1. each created coroutine has a handle, you can join it to get the result, or just wait it to finish

  2. you can cancel or kill a coroutine by

    unsafe { j.coroutine().cancel() };
  3. May also support scoped version spawn. which would block until all the scoped coroutine finished. ref example

  4. the join! macro would block until all the block finish, it's basically a scoped spawn for convenience. ref example

  5. the select! macro block until any coroutine finish. ref example

  6. there is also advanced sub coroutine control mechanism called cqueue which is the underlying implementation of the previous macros.