ealmansi/set-interval-async

clearIntervalAsync inside setIntervalAsync callback stops the execution

Closed this issue · 1 comments

It seems that calling clearIntervalAsync from a setIntervalAsync callback will successfully stop the interval, but also stop the execution of the callback.

It may be related to #20

example.js:

const { clearIntervalAsync } = require('set-interval-async');
const { setIntervalAsync } = require('set-interval-async/dynamic');

let n = 0;
const timer = setIntervalAsync(async () => {
  if (n === 3) {
    await clearIntervalAsync(timer);
    console.log('this statement will not be executed');
  } else {
    console.log('tick');
    n += 1;
  }
}, 100);
$ npm i set-interval-async
$ node example.js
tick
tick
tick

The console.log after the clearIntervalAsync is never executed (or any other kind of code).

I should have read the README 🤣