Add a max setTimout for expiring messages (over max == immediate)
Discovered a user log where expiring message checks were happening constantly. This ensures that a very large timeout doesn't roll over into immediate callbacks. FREEBIE
This commit is contained in:
parent
e57f155403
commit
e7450fa0d7
1 changed files with 5 additions and 0 deletions
|
@ -31,8 +31,13 @@
|
||||||
console.log('next message expires', new Date(expires_at).toISOString());
|
console.log('next message expires', new Date(expires_at).toISOString());
|
||||||
|
|
||||||
var wait = expires_at - Date.now();
|
var wait = expires_at - Date.now();
|
||||||
|
|
||||||
|
// In the past
|
||||||
if (wait < 0) { wait = 0; }
|
if (wait < 0) { wait = 0; }
|
||||||
|
|
||||||
|
// Too far in the future, since it's limited to a 32-bit value
|
||||||
|
if (wait > 2147483647) { wait = 2147483647; }
|
||||||
|
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
timeout = setTimeout(destroyExpiredMessages, wait);
|
timeout = setTimeout(destroyExpiredMessages, wait);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue