@repeaterjs/repeater
3.1.0 · 8 Jun 2026MIT15M / weekRepositoryHomepagenpmAtom feed
3.1.0 is the newest release of 3.x.
In short
8 changed
Release note
repeater@3.0.0 2019-11-10
This release overhauls the push and stop promises and the return and throw methods to be more in line with the behavior of async generators. If you used repeaters to simply add and remove event handlers, you can upgrade without worrying about breaking changes. However, if you awaited push calls, read the value of the stop promise, or used the return or throw methods in non-trivial ways, this release may break your code.
Changed
Previously, the n-th call to
pushresolved to the value passed to the n-th call toRepeater.prototype.next. This was inaccurate insofar as async generators resume the n-thyieldwith the value passed to the n+1-th call tonext. Additionally, async generators completely ignore the first value passed tonextentirely. The former behavior of repeaters was confusing insofar as the first call topushwould always resolve immediately, becausepushcould not be called untilnextwas called for the first time. In 3.0, the behavior has now been changed so that the n-th call topushresolves to the n+1-th call tonext.For the most part, code which awaits
pushwill work as expected, except when the code relied on the first call topushresolving immediately. To make sure you’re not relying on the old behavior ofpush, you should make sure that you await push at the bottom of loops, rather than the top. See the changes totimersas an example.Calling
Repeater.prototype.throwwill now cause the previouspushcall to reject, rather than simply stopping the repeater and throwing the error. This means errors thrown into repeaters are now recoverable. If you call push without awaiting or callingthen/catchon the returned promise and then call thethrowmethod, the repeater will rethrow the error, preserving the previous behavior. However, if you awaitpushor otherwise call thethenorcatchmethods, it becomes your responsibility to handle errors thrown in viathrowand stop the repeater. #43The
stoppromise no longer resolves to the value passed toRepeater.prototype.return. Instead, it consistently fulfills toundefinedwhen the repeater is stopped. Additionally, callingRepeater.prototype.returnwill return a result whose value is always whatever was passed toreturn. In the case of premature returns, the return value of the executor is ignored unless it throws an error. #41This change was made because there is no way with async generators to inspect the value passed to return from within the async generator. Additionally, the only way to modify the result returned from the
returnmethod would be to put areturnstatement in afinallyblock within the async generator, which is typically considered to be a bad practice. Repeaters now uniformly return the value passed to thereturnmethod. See #40 for a longer explanation for why we made this change.Errors thrown by the executor now take priority over rejections passed to push. If a pushed promise rejects, the repeater will await the execution result and throw an error thrown by the executor instead of the rejected promise.
Changes to combinator methods
Improved type inference for
Repeater.raceandRepeater.mergeRepeater.mergeyields non-iterable values, so you can call merge on an iterable of promises to get an async iterator which produces values as each promise fulfills.Iterables passed to combinator methods are upgraded to async iterators, so that promise-like values are awaited and unwrapped before being pushed to the repeater
Changes to typescript typings:
Repeater,RepeaterExecutor,Pushand other related types now take the type parametersTReturnandTNextin line with typescript 3.6’s strict async generator typings.The
RepeaterBufferinterface and concrete classes no longer accept a type parameter. All places where the type parameter would have been used,unknownis used instead. You should never directly add or remove values from buffers.The typings of the
nextandreturnmethods have been changed to acceptPromiseLike<T>andPromiseLike<TReturn>respectively as parameters.
A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.