Registers a callback that is invoked synchronously for every subsequent emit() call.
Function to call with each emitted GraphEvent.
Removes a previously registered listener. If the listener was not registered, this is a no-op.
The exact function reference passed to on().
Dispatches event to all registered listeners and any active stream() generators.
If close() has already been called, this method is a no-op.
The GraphEvent to dispatch.
Returns an AsyncGenerator that yields every GraphEvent emitted after the
call to stream(), in the exact order they were emitted.
The generator completes (returns) when close() is called on the emitter
and any queued events have been yielded.
Multiple concurrent stream() calls are supported; each gets an independent
copy of the event stream.
for await (const event of emitter.stream()) {
if (event.type === 'run_end') break;
}
Lightweight event emitter for
GraphEventvalues.Supports both:
on()/off()callbacks.stream()async generator.The emitter is single-use: once
close()is called it is permanently closed and subsequentemit()calls are silently ignored.Example