usim
usim copied to clipboard
Guaranteed Postponement Context
Short description of the feature Provide a context that postpones exactly once, even when nested. This would allow combining multiple high-level calls as a quasi-atomic async operation.
This is intended as a helper for creating high-level operations. It is required to build new abstractions; users of existing abstractions do not need it.
Describe the solution you'd like
Add an async with
context that opens a postponement scope or resumes an outer one. The outermost context will postpone if it is exited at the same time and turn as it was entered. Nested scopes delegate the responsibility to outer scopes.
Postponement is dynamically scoped, meaning that any postponement in an __await__
, __aenter__
/__aexit__
or __aiter__
/__anext__
is considered nested in any outer postponements.
async with postponed(): # open scope
async with postponed(): # resume scope
await something() # resume scope?
Enforcing only postponement, not suspension, is optional.
Describe alternatives and the context you have considered This has originated from #64. In such a specific case, a special cased implementation could be made. However, these special cases must be carefully constructed to avoid duplicate postponement. Combining several high-level calls is very difficult.