Documentation / @zerotal/flow / index / task
Function: task()
task(
_fn,context):void
Defined in: flow/src/decorators.ts:705
Marks an async method as a streaming, cancellable task. Implicitly @expose (callable from the
browser).
Parameters
_fn
unknown
context
ClassMethodDecoratorContext
Returns
void
Remarks
While a @task runs, the framework flushes throttled partial patches — so incremental field
writes such as this.answer += token appear live in the client — keeps the triggering control
in its loading state for the whole duration, and exposes this.signal (an AbortSignal) that
this.cancel() on the client trips for cooperative cancellation. Because it auto-exposes, no
separate @expose is needed. Applies to a (typically async) method.
Example
class Chat extends Component {
@expose answer = "";
@task async ask(prompt: string) {
for await (const token of streamCompletion(prompt, this.signal)) {
this.answer += token; // each write streams to the client
}
}
}