thread-sleep
TypeScript icon, indicating that this package has built-in type declarations

2.2.0 • Public • Published

thread-sleep

A native module for when you just need node to back off for a few milliseconds. It effectively pauses the current thread. It may be woken early if an interupt is fired, so it should work pretty well for busy waiting scenarios where you want to check something every few hunderd milliseconds.

Linux and Mac Build Status Windows Build Status Dependency Status NPM version

Installation

npm install thread-sleep

This module uses node-pre-gyp so it should install even without a compiler in most environments. If you run into any problems, please open an issue with the full npm log, and a description of what operating system you use.

Usage

var sleep = require('thread-sleep');
 
var start = Date.now();
var res = sleep(1000);
var end = Date.now();
// res is the actual time that we slept for
console.log(res + ' ~= ' + (end - start) + ' ~= 1000');
// tested on osx and resulted in => 1005 ~= 1010 ~= 1000

License

MIT

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i thread-sleep

      Weekly Downloads

      1,318

      Version

      2.2.0

      License

      MIT

      Unpacked Size

      5.58 kB

      Total Files

      8

      Last publish

      Collaborators

      • forbeslindesay
      • timothygu