try-thread-sleep
Version:
Use thread-sleep if native compilation succeeded, otherwise it's a noop
21 lines (19 loc) • 565 B
JavaScript
try {
module.exports = require('thread-sleep');
module.exports.native = true;
} catch (ex) {
module.exports = function (milliseconds) {
var start = Date.now();
if (milliseconds !== (milliseconds | 0)) {
throw new TypeError('sleep only accepts an integer number of milliseconds');
}
milliseconds = milliseconds | 0;
if (milliseconds < 0) {
throw new TypeError('sleep only accepts a positive number of milliseconds');
}
var end = Date.now();
return end - start;
};
module.exports.native = false;
}
;