{"action":"created","issue":{"url":"https://api.github.com/repos/nodejs/node/issues/3512","labels_url":"https://api.github.com/repos/nodejs/node/issues/3512/labels{/name}","comments_url":"https://api.github.com/repos/nodejs/node/issues/3512/comments","events_url":"https://api.github.com/repos/nodejs/node/issues/3512/events","html_url":"https://github.com/nodejs/node/pull/3512","id":113202489,"number":3512,"title":"doc: add note about timeout delay > TIMEOUT_MAX","user":{"login":"sitegui","id":2801575,"avatar_url":"https://avatars.githubusercontent.com/u/2801575?v=3","gravatar_id":"","url":"https://api.github.com/users/sitegui","html_url":"https://github.com/sitegui","followers_url":"https://api.github.com/users/sitegui/followers","following_url":"https://api.github.com/users/sitegui/following{/other_user}","gists_url":"https://api.github.com/users/sitegui/gists{/gist_id}","starred_url":"https://api.github.com/users/sitegui/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sitegui/subscriptions","organizations_url":"https://api.github.com/users/sitegui/orgs","repos_url":"https://api.github.com/users/sitegui/repos","events_url":"https://api.github.com/users/sitegui/events{/privacy}","received_events_url":"https://api.github.com/users/sitegui/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/nodejs/node/labels/doc","name":"doc","color":"006b75"},{"url":"https://api.github.com/repos/nodejs/node/labels/lts-watch-v4.x","name":"lts-watch-v4.x","color":"eb6420"},{"url":"https://api.github.com/repos/nodejs/node/labels/timers","name":"timers","color":"f7c6c7"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-10-25T02:45:06Z","updated_at":"2015-10-27T22:58:37Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/nodejs/node/pulls/3512","html_url":"https://github.com/nodejs/node/pull/3512","diff_url":"https://github.com/nodejs/node/pull/3512.diff","patch_url":"https://github.com/nodejs/node/pull/3512.patch"},"body":"When setTimeout() and setInterval() are called with `delay` greater than TIMEOUT_MAX (2147483647), the supplied value is ignored and 1 is used instead. This adds a note about this in the timers docs.\r\n\r\nI actually got surprised by this behavior when trying to schedule a job to run in the first day of every month:\r\n```js\r\nfunction schedule() {\r\n    var now = new Date\r\n    var nextMonth = new Date(now.getFullYear(), now.getMonth()+1)\r\n    setTimeout(function () {\r\n        shedule()\r\n        doStuff()\r\n    }, nextMonth - now)\r\n}\r\n```\r\n\r\nIt worked the first time, but afterwards it seemed to enter an infinite loop. I only found out why after searching and reading the [timers.js code](https://github.com/nodejs/node/blob/3eecdf9f1422640c7439507cb39ffb3dff57b3e4/lib/timers.js#L181-L183).\r\nIt only worked at first because it was past the 5th day of that month ;)\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/nodejs/node/issues/comments/151669361","html_url":"https://github.com/nodejs/node/pull/3512#issuecomment-151669361","issue_url":"https://api.github.com/repos/nodejs/node/issues/3512","id":151669361,"user":{"login":"bnoordhuis","id":275871,"avatar_url":"https://avatars.githubusercontent.com/u/275871?v=3","gravatar_id":"","url":"https://api.github.com/users/bnoordhuis","html_url":"https://github.com/bnoordhuis","followers_url":"https://api.github.com/users/bnoordhuis/followers","following_url":"https://api.github.com/users/bnoordhuis/following{/other_user}","gists_url":"https://api.github.com/users/bnoordhuis/gists{/gist_id}","starred_url":"https://api.github.com/users/bnoordhuis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bnoordhuis/subscriptions","organizations_url":"https://api.github.com/users/bnoordhuis/orgs","repos_url":"https://api.github.com/users/bnoordhuis/repos","events_url":"https://api.github.com/users/bnoordhuis/events{/privacy}","received_events_url":"https://api.github.com/users/bnoordhuis/received_events","type":"User","site_admin":false},"created_at":"2015-10-27T22:58:37Z","updated_at":"2015-10-27T22:58:37Z","body":"> it will wrap\r\n\r\nBrowsers don't wrap (in the modulo sense), they expire the timer immediately.  If you enter the following in the web console:\r\n\r\n```javascript\r\n> setTimeout(() => console.log('two'), 60e3 + Math.pow(2,31)); setTimeout(() => console.log('one'), Math.pow(2,31))\r\n1\r\ntwo\r\none\r\n```\r\n\r\nWhile with modulo arithmetic it would print \"one two\" (with a 60 second delay between them.)\r\n\r\nI added TIMEOUT_MAX way back because someone complained node was different from the browser, so apparently it's relevant at least to some people."}}