jamboree / co2

A C++ await/yield emulation library for stackless coroutine
334 stars 32 forks source link

What do you expect when a task is cancelled? #1

Closed jamboree closed 9 years ago

jamboree commented 9 years ago

A task (or more general, a coroutine) is cancelled when its ref-count becomes zero or cancellation_requested() returns true. A task is responsible for notifying the waiting coroutine(s), that is, when the result arrives (either value or error), its dependant(s) should get notified. But what if the result never arrives (i.e. when the task is cancelled)? There're some design options:

When a task is cancelled...

  1. Don't call finalize after stack-unwinding, in this case, finalize may need a better name
  2. In finalize, check whether there's a result, if not, do nothing
  3. Let a task's result default to an error state so there's always a result
jamboree commented 9 years ago

Add a cancel customization point and we're done, this is implemented in v2.