Iterate Evented Stream
Create an AsyncIterable
from an evented stream.
Usage Examples
All code snippets below work in an async context.
EventEmitter
Custom In order for an EventEmitter
to be a valid EventTarget
,
-
It must listen to 3 required events:
('data', string)
('error', Error)
('close')
-
It must provide 2 required methods for each event:
addListener
removeListener
-
Iteration stops when the
EventEmitter
emits'close'
or'error'
- If it emits
'close'
, iteration is considered completed. - If it emits
'error'
, iteration throws the emitted error.
- If it emits
const EventEmitter = const iterate = const emitter = for await const chunk of console
Expected Result:
100 ms
200 ms
300 ms
400 ms
Child Process
NOTE: Replace foo
, bar
and baz
below with commands that exist.
const spawn = const combine = const iterate = const cps = 'foo' 'bar' 'baz' const stream = for await const stream chunk of console console