README

peter-jerry-ye/codex/generator does not have a README file

#
Return

pub suberror Return

Error indicating that the async generator should return

#
Running

pub suberror Running

Error indicating that the async generator is already running and cannot accept new operations.

#
AsyncGenerator

type AsyncGenerator[T]

Asynchronous generator producing values of type T.

Similar to JavaScript's async generators, but with explicit handling of return and throw.

The generator must be drained to completion to avoid resource leaks.

#
AsyncGenerator::new

fn[T, G] AsyncGenerator::new(f : async (async (T) -> Unit) -> Unit, taskgroup :
TaskGroup
[G], no_wait? : Bool) -> AsyncGenerator[T]

Creates a new AsyncGenerator from an async function that takes a yield function. The yield function is used to produce values asynchronously.

The generator runs in the provided TaskGroup. If no_wait is true (default), the taskgroup will not wait for the generator to finish when other tasks are done, implicitly cancel it. If no_wait is false, the taskgroup will wait for the generator to finish, potentially blocking shutdown.

It is encouraged to set no_wait to true to avoid resource leaks, and spawn the generator in a dedicated TaskGroup with the consumer.

#
AsyncGenerator::next

async fn[T] AsyncGenerator::next(self : AsyncGenerator[T]) -> T?

#
AsyncGenerator::returns

async fn[T] AsyncGenerator::returns(self : AsyncGenerator[T]) -> T?

Signals the async generator to return, indicating normal completion. Returns the next value or None if the generator completes.

#
AsyncGenerator::throws

async fn[T] AsyncGenerator::throws(self : AsyncGenerator[T], e : Error) -> T?

Throws an error into the async generator, allowing it to handle exceptions. Returns the next value or None if the generator completes.

Source Files