How long can NodeJS `setTimeout` wait?
Can NodeJS setTimeout
delay excecution of function for a week? (assuming the server doesnt go down...)
In some other servers like ASP.NET CORE, the server will sleep when not in use, hence we can't use such.
Does the same happen in the NodeJS world, or the server remains on forever?
javascript node.js server settimeout
add a comment |
Can NodeJS setTimeout
delay excecution of function for a week? (assuming the server doesnt go down...)
In some other servers like ASP.NET CORE, the server will sleep when not in use, hence we can't use such.
Does the same happen in the NodeJS world, or the server remains on forever?
javascript node.js server settimeout
1
It won't go to sleep, but there are better ways of doing that instead of setTimeout
– bambam
Nov 13 '18 at 11:38
2
This is technically possible, but there are definitely better ways of doing this e.g. cron job
– James
Nov 13 '18 at 11:42
If you want something done in an specific date you can use a cron library. The maximum setTimeout time must be defined, if not by other limitations, by the maximum integer JavaScript supports.
– desoares
Nov 13 '18 at 11:42
1
@desoares the largest integer that JS supports is over 285,000 years... (counted in milliseconds)
– Alnitak
Nov 13 '18 at 11:58
add a comment |
Can NodeJS setTimeout
delay excecution of function for a week? (assuming the server doesnt go down...)
In some other servers like ASP.NET CORE, the server will sleep when not in use, hence we can't use such.
Does the same happen in the NodeJS world, or the server remains on forever?
javascript node.js server settimeout
Can NodeJS setTimeout
delay excecution of function for a week? (assuming the server doesnt go down...)
In some other servers like ASP.NET CORE, the server will sleep when not in use, hence we can't use such.
Does the same happen in the NodeJS world, or the server remains on forever?
javascript node.js server settimeout
javascript node.js server settimeout
edited Nov 13 '18 at 11:37
eisbehr
9,94242243
9,94242243
asked Nov 13 '18 at 11:36
McKabueMcKabue
5961616
5961616
1
It won't go to sleep, but there are better ways of doing that instead of setTimeout
– bambam
Nov 13 '18 at 11:38
2
This is technically possible, but there are definitely better ways of doing this e.g. cron job
– James
Nov 13 '18 at 11:42
If you want something done in an specific date you can use a cron library. The maximum setTimeout time must be defined, if not by other limitations, by the maximum integer JavaScript supports.
– desoares
Nov 13 '18 at 11:42
1
@desoares the largest integer that JS supports is over 285,000 years... (counted in milliseconds)
– Alnitak
Nov 13 '18 at 11:58
add a comment |
1
It won't go to sleep, but there are better ways of doing that instead of setTimeout
– bambam
Nov 13 '18 at 11:38
2
This is technically possible, but there are definitely better ways of doing this e.g. cron job
– James
Nov 13 '18 at 11:42
If you want something done in an specific date you can use a cron library. The maximum setTimeout time must be defined, if not by other limitations, by the maximum integer JavaScript supports.
– desoares
Nov 13 '18 at 11:42
1
@desoares the largest integer that JS supports is over 285,000 years... (counted in milliseconds)
– Alnitak
Nov 13 '18 at 11:58
1
1
It won't go to sleep, but there are better ways of doing that instead of setTimeout
– bambam
Nov 13 '18 at 11:38
It won't go to sleep, but there are better ways of doing that instead of setTimeout
– bambam
Nov 13 '18 at 11:38
2
2
This is technically possible, but there are definitely better ways of doing this e.g. cron job
– James
Nov 13 '18 at 11:42
This is technically possible, but there are definitely better ways of doing this e.g. cron job
– James
Nov 13 '18 at 11:42
If you want something done in an specific date you can use a cron library. The maximum setTimeout time must be defined, if not by other limitations, by the maximum integer JavaScript supports.
– desoares
Nov 13 '18 at 11:42
If you want something done in an specific date you can use a cron library. The maximum setTimeout time must be defined, if not by other limitations, by the maximum integer JavaScript supports.
– desoares
Nov 13 '18 at 11:42
1
1
@desoares the largest integer that JS supports is over 285,000 years... (counted in milliseconds)
– Alnitak
Nov 13 '18 at 11:58
@desoares the largest integer that JS supports is over 285,000 years... (counted in milliseconds)
– Alnitak
Nov 13 '18 at 11:58
add a comment |
2 Answers
2
active
oldest
votes
Answering your question
setTimeout has the second argument of delay as a 32-bit signed integer. So the value can not be greater than 2147483647 (about 24.8 days). When the delay is larger than 2147483647, then the day will set to 1. (ref)
Answering your use-case
instead of using setTimeout
for such a long delay, you can run cron job.
add a comment |
There is nothing in the documentation that would suggest it would not work. However, if the length in millisecond is greater than 2147483647
(24 day 20 h 31 min 24 s), the delay is set to 1.
https://nodejs.org/api/timers.html#timers_settimeout_callback_delay_args
The behavior is different on a browser. Unsurprisingly, the timeout is delayed if the associated tab is inactive.
If the method context is a Window object, wait until the Document
associated with the method context has been fully active for a further
timeout milliseconds (not necessarily consecutively).
Otherwise, if the method context is a WorkerUtils object, wait until
timeout milliseconds have passed with the worker not suspended (not
necessarily consecutively).
https://www.w3.org/TR/2011/WD-html5-20110525/timers.html#dom-windowtimers-settimeout
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280186%2fhow-long-can-nodejs-settimeout-wait%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Answering your question
setTimeout has the second argument of delay as a 32-bit signed integer. So the value can not be greater than 2147483647 (about 24.8 days). When the delay is larger than 2147483647, then the day will set to 1. (ref)
Answering your use-case
instead of using setTimeout
for such a long delay, you can run cron job.
add a comment |
Answering your question
setTimeout has the second argument of delay as a 32-bit signed integer. So the value can not be greater than 2147483647 (about 24.8 days). When the delay is larger than 2147483647, then the day will set to 1. (ref)
Answering your use-case
instead of using setTimeout
for such a long delay, you can run cron job.
add a comment |
Answering your question
setTimeout has the second argument of delay as a 32-bit signed integer. So the value can not be greater than 2147483647 (about 24.8 days). When the delay is larger than 2147483647, then the day will set to 1. (ref)
Answering your use-case
instead of using setTimeout
for such a long delay, you can run cron job.
Answering your question
setTimeout has the second argument of delay as a 32-bit signed integer. So the value can not be greater than 2147483647 (about 24.8 days). When the delay is larger than 2147483647, then the day will set to 1. (ref)
Answering your use-case
instead of using setTimeout
for such a long delay, you can run cron job.
edited Nov 13 '18 at 11:50
answered Nov 13 '18 at 11:44
Laxmikant DangeLaxmikant Dange
5,42132856
5,42132856
add a comment |
add a comment |
There is nothing in the documentation that would suggest it would not work. However, if the length in millisecond is greater than 2147483647
(24 day 20 h 31 min 24 s), the delay is set to 1.
https://nodejs.org/api/timers.html#timers_settimeout_callback_delay_args
The behavior is different on a browser. Unsurprisingly, the timeout is delayed if the associated tab is inactive.
If the method context is a Window object, wait until the Document
associated with the method context has been fully active for a further
timeout milliseconds (not necessarily consecutively).
Otherwise, if the method context is a WorkerUtils object, wait until
timeout milliseconds have passed with the worker not suspended (not
necessarily consecutively).
https://www.w3.org/TR/2011/WD-html5-20110525/timers.html#dom-windowtimers-settimeout
add a comment |
There is nothing in the documentation that would suggest it would not work. However, if the length in millisecond is greater than 2147483647
(24 day 20 h 31 min 24 s), the delay is set to 1.
https://nodejs.org/api/timers.html#timers_settimeout_callback_delay_args
The behavior is different on a browser. Unsurprisingly, the timeout is delayed if the associated tab is inactive.
If the method context is a Window object, wait until the Document
associated with the method context has been fully active for a further
timeout milliseconds (not necessarily consecutively).
Otherwise, if the method context is a WorkerUtils object, wait until
timeout milliseconds have passed with the worker not suspended (not
necessarily consecutively).
https://www.w3.org/TR/2011/WD-html5-20110525/timers.html#dom-windowtimers-settimeout
add a comment |
There is nothing in the documentation that would suggest it would not work. However, if the length in millisecond is greater than 2147483647
(24 day 20 h 31 min 24 s), the delay is set to 1.
https://nodejs.org/api/timers.html#timers_settimeout_callback_delay_args
The behavior is different on a browser. Unsurprisingly, the timeout is delayed if the associated tab is inactive.
If the method context is a Window object, wait until the Document
associated with the method context has been fully active for a further
timeout milliseconds (not necessarily consecutively).
Otherwise, if the method context is a WorkerUtils object, wait until
timeout milliseconds have passed with the worker not suspended (not
necessarily consecutively).
https://www.w3.org/TR/2011/WD-html5-20110525/timers.html#dom-windowtimers-settimeout
There is nothing in the documentation that would suggest it would not work. However, if the length in millisecond is greater than 2147483647
(24 day 20 h 31 min 24 s), the delay is set to 1.
https://nodejs.org/api/timers.html#timers_settimeout_callback_delay_args
The behavior is different on a browser. Unsurprisingly, the timeout is delayed if the associated tab is inactive.
If the method context is a Window object, wait until the Document
associated with the method context has been fully active for a further
timeout milliseconds (not necessarily consecutively).
Otherwise, if the method context is a WorkerUtils object, wait until
timeout milliseconds have passed with the worker not suspended (not
necessarily consecutively).
https://www.w3.org/TR/2011/WD-html5-20110525/timers.html#dom-windowtimers-settimeout
answered Nov 13 '18 at 11:42
squgeimsqugeim
1,7341915
1,7341915
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53280186%2fhow-long-can-nodejs-settimeout-wait%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
It won't go to sleep, but there are better ways of doing that instead of setTimeout
– bambam
Nov 13 '18 at 11:38
2
This is technically possible, but there are definitely better ways of doing this e.g. cron job
– James
Nov 13 '18 at 11:42
If you want something done in an specific date you can use a cron library. The maximum setTimeout time must be defined, if not by other limitations, by the maximum integer JavaScript supports.
– desoares
Nov 13 '18 at 11:42
1
@desoares the largest integer that JS supports is over 285,000 years... (counted in milliseconds)
– Alnitak
Nov 13 '18 at 11:58