stopButton.addEventListener("click", () => { // Stops the stream and removes the listener. inputEvents.return(); });
pipe( inputEvents, map((event) =>event.target.valueAsNumber), filter((n) => !Number.isNaN(n)), forEach((n) =>console.log(n)), ); // Logs every number after an `input` event.
Note: Because of limitations with async iterators, each
iteration happens in the next tick. This might not be ideal if
event needs to be handle in the same loop. Look into Observable
for a better event driven structure.
Add an iterator by attaching an event listener. Will iterate over every event that fire.
Call
.return()on the returned iterable to remove the listener and return from any running iterators.Note: Because of limitations with async iterators, each iteration happens in the next tick. This might not be ideal if event needs to be handle in the same loop. Look into Observable for a better event driven structure.