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...
Don't call finalize after stack-unwinding, in this case, finalize may need a better name
In finalize, check whether there's a result, if not, do nothing
Let a task's result default to an error state so there's always a result
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...
finalize
after stack-unwinding, in this case,finalize
may need a better namefinalize
, check whether there's a result, if not, do nothing