Relese Notes: v2.0.0
Breaking changes
Error handling
Errors thrown by the handler function passed in to setIntervalAsync
are no longer hidden (swallowed). This will allow users of this library to more easily detect and handle failure within their handlers, which will now raise an UnhandledPromiseRejectionWarning
if not handled by the application itself. If you wish to fall back to the previous behaviour, you may simply wrap your handlers in the following way:
setIntervalAsync(async () => {
try {
await handler(); // the previous handler function which could potentially fail
} catch (err) {
console.error(err);
}
}, someInterval);
// or similarly,
setIntervalAsync(() => {
return Promise.resolve(handler()).catch((err) => console.error(err));
}, someInterval);
Bug fixes
Awaiting clearIntervalAsync
While clearIntervalAsync
was still correctly clearing the execution interval, a bug in version v1.x.x was causing the promise returned by the function to be resolved prematurely before the interval was fully stopped. This bug has now been fixed, which means the following code should work as expected:
it('should test something', async () => {
const timer = setIntervalAsync(...);
// Some assertions.
await clearIntervalAsync(timer);
// At this point, the interval has been cleared and all executions
// are guaranteed to have fully finished.
});