Repeater.js · The missing constructor for creating safe async iterators
source link: https://repeater.js.org/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Convenient
The Repeater
class provides a memorable promise-based API for creating async iterators. You can reuse the same constructor to convert event targets, websockets or any other callback-based data source into a format which can be read using async/await
and for await…of
syntax.
Repeaters prevent common mistakes people make when rolling async iterators by hand. By executing lazily, dealing with backpressure, and propagating errors in a predictable manner, repeaters ensure that event handlers are cleaned up and that bottlenecks and deadlocks are discovered quickly.
Powerful
You can use repeaters to implement architectural patterns like cancelable timers, semaphores, and generic pubsub classes. The Repeater class also defines static methods like Repeater.race
and Repeater.merge
which allow you to use async iterators for reactive programming purposes.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK