chrisguttandin / worker-timers

A replacement for setInterval() and setTimeout() which works in unfocused windows.
MIT License
590 stars 25 forks source link

The behavior of clearInterval and clearTimeout differs from what is written on MDN #437

Closed luccasr73 closed 5 months ago

luccasr73 commented 6 months ago

First of all, thank you for this incredible library! timers in web workers are wonderful and much more reliable

MDN says Passing an invalid ID to clearTimeout() silently does nothing; no exception is thrown but workers-timers throw an error when i pass a invalid id to clearInterval or clearTimeout and this error cannot caught by try-catch, this has caused me some strange infinite loop problems

repro: https://stackblitz.com/edit/vitejs-vite-sg1zde?file=src%2FApp.tsx

chrisguttandin commented 5 months ago

Hi @luccasr73, thanks for reporting this. When looking into it I realized that this behavior even caused a memory on the worker. I aligned the behavior with the one of the native timers. I published the changes as v8.0.0.

The only remaining difference should be that intervals and timeouts are handled separately.

https://github.com/chrisguttandin/worker-timers/blob/10fa538fa531c8173d96e816057629ac6d2112d5/README.md?plain=1#L45-L59

luccasr73 commented 5 months ago

thanks for the fix