Class Stream<T>
Source: stream.ts
A communication channel for process I/O, supporting event-based data transmission, signaling, and piping between streams.
Extends
Type Parameters
T
T = string
Constructors
Constructor
new Stream<
T>():Stream<T>
Returns
Stream<T>
Inherited from
EventEmitter<StreamEvents<T>>.constructor
Properties
DATA_EVENT
readonlystaticDATA_EVENT:"data"="data"
START_EVENT
readonlystaticSTART_EVENT:"start"="start"
STOP_EVENT
readonlystaticSTOP_EVENT:"stop"="stop"
SIGNAL_EVENT
readonlystaticSIGNAL_EVENT:"signal"="signal"
enabled
enabled:
boolean=false
Methods
start()
start(
callback?: (stream:this) =>void):this
Activates the stream and notifies listeners.
Parameters
callback?
(stream: this) => void
Returns
this
stop()
stop():
this
Deactivates the stream. Subsequent calls to Stream.write will be ignored.
Returns
this
signal()
signal(
signal:StreamSignal):this
Emits a control signal. Standard termination signals will automatically stop the stream.
Parameters
signal
Returns
this
write()
write(
data:T):this
Broadcasts data to all listeners if the stream is enabled.
Parameters
data
T
Returns
this
pipe()
pipe(
destination:Stream<T>):Stream<T>
Forwards data, stop events, and signals from this stream to another.
Parameters
destination
Stream<T>
The stream that will receive the forwarded data.
Returns
Stream<T>
The destination stream to allow for chainable piping.
wait()
Call Signature
wait():
Promise<void>
Returns a promise that resolves when the stream is stopped.
Returns
Promise<void>
Call Signature
wait<
U>(value:U):Promise<U>
Returns a promise that resolves when the stream is stopped.
Type Parameters
U
U
Parameters
value
U
Value to return when the promise resolves.
Returns
Promise<U>
on()
on<
K>(event:K,listener:Listener<StreamEvents<T>,K>):Listener<StreamEvents<T>,K>
Starts listening to an event.
Type Parameters
K
K extends keyof StreamEvents<T>
Parameters
event
K
The event to listen to.
listener
Listener<StreamEvents<T>, K>
The function to call when the event is emitted.
Returns
Listener<StreamEvents<T>, K>
The listener.
Inherited from
EventEmitter.on
once()
once<
K>(event:K,listener:Listener<StreamEvents<T>,K>):Listener<StreamEvents<T>,K>
Registers an event listener that is automatically removed when called.
Type Parameters
K
K extends keyof StreamEvents<T>
Parameters
event
K
The event to listen to.
listener
Listener<StreamEvents<T>, K>
The function to call once the event is emitted.
Returns
Listener<StreamEvents<T>, K>
The wrapped listener.
Inherited from
EventEmitter.once
onAsync()
onAsync<
K>(event:K,listener:AsyncListener<StreamEvents<T>,K>,onRejected?: (reason:any) =>unknown|null):Listener<StreamEvents<T>,K>
Starts listening to an event.
Type Parameters
K
K extends keyof StreamEvents<T>
Parameters
event
K
The event to listen to.
listener
AsyncListener<StreamEvents<T>, K>
The function to call when the event is emitted.
onRejected?
(reason: any) => unknown | null
Returns
Listener<StreamEvents<T>, K>
The wrapped listener.
Inherited from
EventEmitter.onAsync
off()
off<
K>(event:K,listener:Listener<StreamEvents<T>,K>):void
Removes an event listener.
Type Parameters
K
K extends keyof StreamEvents<T>
Parameters
event
K
The event to remove the listener from.
listener
Listener<StreamEvents<T>, K>
The listener to remove.
Returns
void
Inherited from
EventEmitter.off
emit()
emit<
K>(event:K, ...args:StreamEvents<T>[K]):void
Emits an event to all its listeners.
Type Parameters
K
K extends keyof StreamEvents<T>
Parameters
event
K
The event to emit.
args
...StreamEvents<T>[K]
The arguments to pass to the listeners.
Returns
void
Inherited from
EventEmitter.emit