momentum
momentum copied to clipboard
Race condition
It's possible for a race condition to occur where a clearTimeout (or clearInterval) is called BEFORE a fire message is handled by the browser thread.
The clearTimeout code in the browser thread deletes e.data.id (or intervalId as it's called there) from $momentum.idToCallback causing an exception in the fire handler.
To fix this, the fire handler should be changed to:
$momentum.worker.onmessage = function (e) {
if (e.data.type === 'fire' && $momentum.idToCallback[e.data.id] != null) {
$momentum.idToCallback[e.data.id]();
}
};