From 0a975c541e3f2dd859a8d7708f8dc686d3010dea Mon Sep 17 00:00:00 2001 From: Forbes Lindesay Date: Thu, 5 Feb 2015 10:20:24 +0000 Subject: [PATCH] Add usage --- README.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 3e2b20e..8df9871 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # thread-sleep -A native module for when you just need node to back off for a few milliseconds +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](https://img.shields.io/travis/ForbesLindesay/thread-sleep/master.svg?label=Linux%20%26%20Mac%20Build)](https://travis-ci.org/ForbesLindesay/thread-sleep) [![Windows Build Status](https://img.shields.io/appveyor/ci/ForbesLindesay/thread-sleep/master.svg?label=Windows%20Build)](https://ci.appveyor.com/project/ForbesLindesay/thread-sleep) @@ -11,6 +11,19 @@ A native module for when you just need node to back off for a few milliseconds npm install thread-sleep +## Usage + +```js +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