You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rename cancel to cancelsuspend. It's only for canceling coroutines which have used the suspend keyword, and they must be in the suspend state, and not running (at least not accessing the coroutine frame).
Add cancelasync which is used for canceling an async function call. This is thread-safe and can be called at any time, even if the coroutine is running. It atomically sets a flag, and then any time the async function would start suspending - this includes doing an await - it instead performs a cancelsuspend on itself.
When a coroutine is destroyed via cancelsuspend (always at a suspend point), it runs the defer and errdefer expressions in scope, and then either does cancelsuspend on the awaiter, or if there is no awaiter yet, sets a flag which the awaiter will discover and perform a cancelsuspend on itself.
So the rule to remember is:
Every use of suspend has the responsibility to have a plan for how some code, somewhere, will either cancelsuspend or resume the handle.
Every use async has the responsibility to make sure that the resulting handle gets cancelasync or await applied to it.
Most user code will use async, await, and cancelasync, however there is occasionally the necessity to use suspend and cancelsuspend.
The text was updated successfully, but these errors were encountered:
andrewrk
added
the
proposal
This issue suggests modifications. If it also has the "accepted" label then it is planned.
label
Jul 18, 2018
Rename
cancel
tocancelsuspend
. It's only for canceling coroutines which have used thesuspend
keyword, and they must be in the suspend state, and not running (at least not accessing the coroutine frame).Add
cancelasync
which is used for canceling anasync
function call. This is thread-safe and can be called at any time, even if the coroutine is running. It atomically sets a flag, and then any time the async function would start suspending - this includes doing an await - it instead performs acancelsuspend
on itself.When a coroutine is destroyed via
cancelsuspend
(always at a suspend point), it runs thedefer
anderrdefer
expressions in scope, and then either doescancelsuspend
on the awaiter, or if there is no awaiter yet, sets a flag which the awaiter will discover and perform acancelsuspend
on itself.So the rule to remember is:
suspend
has the responsibility to have a plan for how some code, somewhere, will eithercancelsuspend
orresume
the handle.async
has the responsibility to make sure that the resulting handle getscancelasync
orawait
applied to it.Most user code will use
async
,await
, andcancelasync
, however there is occasionally the necessity to usesuspend
andcancelsuspend
.The text was updated successfully, but these errors were encountered: