How long can NodeJS `setTimeout` wait?












3















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?










share|improve this question




















  • 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


















3















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?










share|improve this question




















  • 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
















3












3








3








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?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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
















  • 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














2 Answers
2






active

oldest

votes


















2















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.






share|improve this answer

































    3














    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







    share|improve this answer























      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
      });


      }
      });














      draft saved

      draft discarded


















      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









      2















      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.






      share|improve this answer






























        2















        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.






        share|improve this answer




























          2












          2








          2








          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.






          share|improve this answer
















          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.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 13 '18 at 11:50

























          answered Nov 13 '18 at 11:44









          Laxmikant DangeLaxmikant Dange

          5,42132856




          5,42132856

























              3














              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







              share|improve this answer




























                3














                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







                share|improve this answer


























                  3












                  3








                  3







                  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







                  share|improve this answer













                  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








                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 13 '18 at 11:42









                  squgeimsqugeim

                  1,7341915




                  1,7341915






























                      draft saved

                      draft discarded




















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      Bressuire

                      Vorschmack

                      Quarantine