Skip to main content

StaticJsAsyncGenerator

A sandboxed async generator object.

Import

import { type StaticJsAsyncGenerator, isStaticJsAsyncGenerator } from "@suntime-js/core";

Extends

StaticJsObjectStaticJsPrimitive


Overview

StaticJsAsyncGenerator represents the async generator object returned when a sandboxed async generator function is called (e.g. async function* gen() { ... }). It implements the ECMAScript async generator protocol — next, return, and throw — each available in three variants following the same triplet pattern used by StaticJsObject.

Unlike StaticJsGenerator, each step returns a StaticJsPromise rather than a direct result record. The promise resolves to an iterator result object inside the sandbox once the generator resumes.

The *Sync and *Async variants accept an optional StaticJsRunTaskOptions to override the task runner; the *Evaluator variants do not.


Properties

Inherits all properties from StaticJsObject.

typeOf

"object"

runtimeTypeOf

"async-generator"


Methods

Inherits all methods from StaticJsObject.

next(value?, opts?)

nextSync(value?: StaticJsValue, opts?: StaticJsRunTaskOptions): StaticJsPromise
nextAsync(value?: StaticJsValue, opts?: StaticJsRunTaskOptions): Promise<StaticJsPromise>
nextEvaluator(value?: StaticJsValue): EvaluationGenerator<StaticJsPromise>

Resumes the async generator, passing value as the result of the current await or yield expression. Returns a StaticJsPromise that resolves inside the sandbox to the next iterator result object.

On the first call, value is ignored (as per the ECMAScript spec).

return(value?, opts?)

returnSync(value?: StaticJsValue, opts?: StaticJsRunTaskOptions): StaticJsPromise
returnAsync(value?: StaticJsValue, opts?: StaticJsRunTaskOptions): Promise<StaticJsPromise>
returnEvaluator(value?: StaticJsValue): EvaluationGenerator<StaticJsPromise>

Terminates the async generator early, running any finally blocks. Returns a StaticJsPromise that resolves to a result record with done: true and the provided value.

throw(value, opts?)

throwSync(value: StaticJsValue, opts?: StaticJsRunTaskOptions): StaticJsPromise
throwAsync(value: StaticJsValue, opts?: StaticJsRunTaskOptions): Promise<StaticJsPromise>
throwEvaluator(value: StaticJsValue): EvaluationGenerator<StaticJsPromise>

Resumes the async generator by throwing value at the current suspension point. Returns a StaticJsPromise that either resolves to the next iterator result (if the generator handles the error) or rejects with value (if unhandled).


Type guard

isStaticJsAsyncGenerator(value)

isStaticJsAsyncGenerator(value: unknown): value is StaticJsAsyncGenerator

See also