Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Javascript sleep

Javascript sleep

Scheduled Pinned Locked Moved The Weird and The Wonderful
javascriptcom
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Andy Brummer
    wrote on last edited by
    #1

    function sleep(milliSeconds) {
    var startTime = new Date().getTime(); // get the current time
    while (new Date().getTime() < startTime + milliSeconds); // hog cpu
    }

    function verifySleep(milliSeconds) {
    // wrapper function so add time tracking for demo
    var startTime = new Date().getTime(); // get the current time
    sleep(milliSeconds);
    alert('blocked for ' + ((new Date().getTime()) - startTime) + ' milli seconds');
    }

    Curvature of the Mind now with 3D

    P 1 Reply Last reply
    0
    • A Andy Brummer

      function sleep(milliSeconds) {
      var startTime = new Date().getTime(); // get the current time
      while (new Date().getTime() < startTime + milliSeconds); // hog cpu
      }

      function verifySleep(milliSeconds) {
      // wrapper function so add time tracking for demo
      var startTime = new Date().getTime(); // get the current time
      sleep(milliSeconds);
      alert('blocked for ' + ((new Date().getTime()) - startTime) + ' milli seconds');
      }

      Curvature of the Mind now with 3D

      P Offline
      P Offline
      Peter_in_2780
      wrote on last edited by
      #2

      What's wrong with that? That's how scroll lock was implemented in the original PC BIOS (and no doubt a zillion clones). Back in the good ol' days, IBM actually published BIOS listings! Cheers, Peter ;P

      Software rusts. Simon Stephenson, ca 1994.

      J 1 Reply Last reply
      0
      • P Peter_in_2780

        What's wrong with that? That's how scroll lock was implemented in the original PC BIOS (and no doubt a zillion clones). Back in the good ol' days, IBM actually published BIOS listings! Cheers, Peter ;P

        Software rusts. Simon Stephenson, ca 1994.

        J Offline
        J Offline
        Jeroen De Dauw
        wrote on last edited by
        #3

        Presumably the intention is to suspend the thread and not hog the CPU, in which case you should use setTimeout.

        Jeroen De Dauw
        Blog ; Wiki

        P 1 Reply Last reply
        0
        • J Jeroen De Dauw

          Presumably the intention is to suspend the thread and not hog the CPU, in which case you should use setTimeout.

          Jeroen De Dauw
          Blog ; Wiki

          P Offline
          P Offline
          Peter_in_2780
          wrote on last edited by
          #4

          Missed the joke icon?

          Software rusts. Simon Stephenson, ca 1994.

          J 1 Reply Last reply
          0
          • P Peter_in_2780

            Missed the joke icon?

            Software rusts. Simon Stephenson, ca 1994.

            J Offline
            J Offline
            Jeroen De Dauw
            wrote on last edited by
            #5

            :omg: yeah :)

            Jeroen De Dauw
            Blog ; Wiki

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups