tiper-js icon indicating copy to clipboard operation
tiper-js copied to clipboard

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

Open ealmansi opened this issue 3 years ago • 1 comments

Hi @carlelieser.

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, 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 tiper-js, the pattern is hidden in the following sequence initializeTypingInterval > setIntervalAsync > insertCurrentChar > stopTyping > 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.

ealmansi avatar Mar 29 '21 14:03 ealmansi

Hey @ealmansi, thanks for the heads up! I'll update it and take a look.

carlelieser avatar Mar 29 '21 15:03 carlelieser