sleep-promise
Advanced tools
Comparing version 7.1.0 to 8.0.0
@@ -9,5 +9,5 @@ import { SleepOptions } from './shared'; | ||
timeout: number, | ||
options: SleepOptions = {}, | ||
options?: SleepOptions, | ||
): Promise<T> & ((value: T) => T); | ||
export = sleep; |
@@ -1,40 +0,1 @@ | ||
'use strict'; | ||
// Store a reference to the global setTimeout, | ||
// in case it gets replaced (e.g. sinon.useFakeTimers()) | ||
var cachedSetTimeout = setTimeout; | ||
function createSleepPromise(timeout) { | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
useCachedSetTimeout = _ref.useCachedSetTimeout; | ||
var timeoutFunction = useCachedSetTimeout ? cachedSetTimeout : setTimeout; | ||
return new Promise(function (resolve) { | ||
timeoutFunction(resolve, timeout); | ||
}); | ||
} | ||
function sleep(timeout) { | ||
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
useCachedSetTimeout = _ref2.useCachedSetTimeout; | ||
var sleepPromise = createSleepPromise(timeout, { | ||
useCachedSetTimeout: useCachedSetTimeout | ||
}); // Pass value through, if used in a promise chain | ||
function promiseFunction(value) { | ||
return sleepPromise.then(function () { | ||
return value; | ||
}); | ||
} // Normal promise | ||
promiseFunction.then = function () { | ||
return sleepPromise.then.apply(sleepPromise, arguments); | ||
}; | ||
promiseFunction.catch = Promise.resolve().catch; | ||
return promiseFunction; | ||
} | ||
module.exports = sleep; | ||
'use strict';var cachedSetTimeout=setTimeout;function createSleepPromise(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},c=b.useCachedSetTimeout,d=c?cachedSetTimeout:setTimeout;return new Promise(function(b){d(b,a)})}function sleep(a){function b(a){return e.then(function(){return a})}var c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},d=c.useCachedSetTimeout,e=createSleepPromise(a,{useCachedSetTimeout:d});return b.then=function(){return e.then.apply(e,arguments)},b.catch=Promise.resolve().catch,b}module.exports=sleep; |
@@ -5,5 +5,5 @@ import { SleepOptions } from './shared'; | ||
timeout: number, | ||
options: SleepOptions = {}, | ||
options?: SleepOptions, | ||
): Promise<T> & ((value: T) => T); | ||
export default sleep; |
{ | ||
"name": "sleep-promise", | ||
"version": "7.1.0", | ||
"author": "Jan Brummelte <sleep-promise@jan-brummelte.de> (https://jan-brummelte.de)", | ||
"version": "8.0.0", | ||
"description": "Resolves a promise after a specified delay.", | ||
@@ -9,6 +10,7 @@ "main": "build/cjs.js", | ||
"scripts": { | ||
"test": "npm run test:code && npm run test:eslint && npm run test:formatting", | ||
"test": "npm run test:code && npm run test:eslint && npm run test:formatting && npm run test:typescript", | ||
"test:code": "jest", | ||
"test:eslint": "eslint \"lib/**/*.js\"", | ||
"test:formatting": "prettier-eslint --list-different \"lib/**/*.js\" \"types/**/*.d.ts\"", | ||
"test:typescript": "tsc", | ||
"build": "npm run build:clean && npm run build:bundle && npm run build:types", | ||
@@ -29,3 +31,2 @@ "build:clean": "rimraf build", | ||
], | ||
"author": "Jan Brummelte <sleep-promise@jan-brummelte.de> (http://jan-brummelte.de)", | ||
"license": "MIT", | ||
@@ -37,18 +38,20 @@ "bugs": { | ||
"devDependencies": { | ||
"@babel/cli": "^7.0.0-beta.44", | ||
"@babel/core": "^7.0.0-beta.44", | ||
"@babel/preset-env": "^7.0.0-beta.44", | ||
"@babel/cli": "^7.0.0-beta.49", | ||
"@babel/core": "^7.0.0-beta.49", | ||
"@babel/preset-env": "^7.0.0-beta.49", | ||
"@brummelte/eslint-config": "^3.0.0", | ||
"babel-core": "^7.0.0-0", | ||
"babel-jest": "^22.4.3", | ||
"babel-jest": "^23.0.1", | ||
"copyfiles": "^2.0.0", | ||
"eslint": "^4.19.1", | ||
"jest": "^22.4.3", | ||
"jest-junit": "^3.6.0", | ||
"jest": "^23.1.0", | ||
"jest-junit": "^5.0.0", | ||
"prettier-eslint-cli": "^4.7.1", | ||
"rimraf": "^2.6.2", | ||
"rollup": "^0.57.1", | ||
"rollup-plugin-babel": "^4.0.0-beta.3", | ||
"rollup-plugin-node-resolve": "^3.3.0" | ||
"rollup": "^0.60.0", | ||
"rollup-plugin-babel": "^4.0.0-beta.4", | ||
"rollup-plugin-babel-minify": "^5.0.0", | ||
"rollup-plugin-node-resolve": "^3.3.0", | ||
"typescript": "^2.9.1" | ||
} | ||
} |
@@ -68,10 +68,15 @@ # sleep-promise | ||
async(() => { | ||
await sleep(2000); | ||
(async () => { | ||
// 2 seconds faked by sinon | ||
const sleepPromise = sleep(2000); | ||
clock.tick(2000); | ||
console.log('instant, 2 seconds faked by sinon'); | ||
await sleepPromise; | ||
console.log('instant'); | ||
await sleep(2000, { useCachedSetTimeout: true }); | ||
console.log('2 seconds later, cached global setTimeout before sinon replaced it'); | ||
// Caches global setTimeout before sinon replaced it | ||
const sleepPromise2 = sleep(2000, { useCachedSetTimeout: true }); | ||
clock.tick(2000); | ||
await sleepPromise2; | ||
console.log('2 seconds later'); | ||
})(); | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
193437
82
17
24