|
Uni20
Asynchronous tensor and runtime library.
|
This page collects common patterns for Uni20 async coroutines.
If you are new to the runtime, start with getting_started.md and coroutines_primer.md.
Default Async<T> starts unconstructed. First write is usually simplest as proxy assignment.
When input and output are different Async<T> objects, this is the simplest kernel shape:
Use one WriteBuffer for exclusive access to the existing value:
The mutable-reference path requires an existing value. When initialize-or-add semantics are intended, proxy += can construct an absent value:
A ReadBuffer plus a WriteBuffer from the same queue denotes two epochs, not one read/write lock. Use that only for a deliberate read-then-write transition that copies its input and releases the reader before waiting for the writer.
This is C++ operator precedence. Unary co_await binds tighter than assignment:
This is valid on first write to default-constructed Async<T> when the source can both construct and assign T. Once the value exists, proxy assignment evaluates stored_value = value instead of reconstructing it.
Unhandled exceptions in a coroutine can be forwarded to registered sink epochs.
Common pattern: a reader failure should invalidate the output writer epoch.
If you want "no value" to behave like cancellation, use or_cancel():
Use DebugScheduler first. It runs tasks in deterministic order and dumps task/epoch state on deadlock.
Environment variable:
UNI20_DEBUG_ASYNC_TASKS=full for maximum TaskRegistry dump outputDocs: