aio-rek icon indicating copy to clipboard operation
aio-rek copied to clipboard

Heads up about new major version of set-interval-async

Open ealmansi opened this issue 5 years ago • 0 comments

Hi @jefrydco.

A new version of set-interval-async is available with improvements on error handling and including a bug fix. You may see the changes in more detail in the release notes.

I'm reaching out because I noticed an instance of the following pattern in your project (link), which may lead to undesired results:

const timer = setIntervalAsync(async () => {
  // ...
  if (/* some condition */) {
    await clearIntervalAsync(timer);
  }
}, interval);

The code above generates a chaining promise cycle which never resolves, because:

  • await clearIntervalAsync(timer) will not resolve until the last execution has finished, AND
  • the last execution will not finish until await clearIntervalAsync(timer) has been resolved.

In aio-rek, the pattern is hidden in the following sequence: initFaceDetection > setIntervalAsync > clearFaceDetection > clearIntervalAsync. Simply not awaiting clearIntervalAsync may be enough to avoid this issue, but the right solution will depend on your application's requirements. This didn't surface earlier due to the bug in set-interval-async that has now been fixed in the latest major version.

Best, Emilio

ealmansi avatar Mar 29 '21 15:03 ealmansi