p-min-delay
Advanced tools
Comparing version 2.0.0 to 3.0.0
24
index.js
'use strict'; | ||
const delay = require('delay'); | ||
module.exports = (promise, ms, opts) => { | ||
opts = Object.assign({ | ||
delayRejection: true | ||
}, opts); | ||
const pMinDelay = async (promise, minimumDelay, options) => { | ||
options = { | ||
delayRejection: true, | ||
...options | ||
}; | ||
let promiseErr; | ||
let promiseError; | ||
if (opts.delayRejection) { | ||
promise = promise.catch(err => { | ||
promiseErr = err; | ||
if (options.delayRejection) { | ||
promise = promise.catch(error => { | ||
promiseError = error; | ||
}); | ||
} | ||
return Promise.all([promise, delay(ms)]) | ||
.then(val => promiseErr ? Promise.reject(promiseErr) : val[0]); | ||
const value = await Promise.all([promise, delay(minimumDelay)]); | ||
return promiseError ? Promise.reject(promiseError) : value[0]; | ||
}; | ||
module.exports = pMinDelay; | ||
module.exports.default = pMinDelay; |
103
package.json
{ | ||
"name": "p-min-delay", | ||
"version": "2.0.0", | ||
"description": "Delay a promise a minimum amount of time", | ||
"license": "MIT", | ||
"repository": "sindresorhus/p-min-delay", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"promise", | ||
"delay", | ||
"minimum", | ||
"min", | ||
"resolve", | ||
"stall", | ||
"defer", | ||
"wait", | ||
"timeout", | ||
"settimeout", | ||
"event", | ||
"loop", | ||
"next", | ||
"tick", | ||
"delay", | ||
"async", | ||
"await", | ||
"promises", | ||
"bluebird" | ||
], | ||
"dependencies": { | ||
"delay": "^1.3.1" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"in-range": "^1.0.0", | ||
"time-span": "^1.0.0", | ||
"xo": "*" | ||
}, | ||
"xo": { | ||
"esnext": true | ||
} | ||
"name": "p-min-delay", | ||
"version": "3.0.0", | ||
"description": "Delay a promise a minimum amount of time", | ||
"license": "MIT", | ||
"repository": "sindresorhus/p-min-delay", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava && tsd-check" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"keywords": [ | ||
"promise", | ||
"delay", | ||
"minimum", | ||
"min", | ||
"resolve", | ||
"stall", | ||
"defer", | ||
"wait", | ||
"timeout", | ||
"settimeout", | ||
"event", | ||
"loop", | ||
"next", | ||
"tick", | ||
"delay", | ||
"async", | ||
"await", | ||
"promises", | ||
"bluebird" | ||
], | ||
"dependencies": { | ||
"delay": "^4.1.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^1.3.1", | ||
"in-range": "^1.0.0", | ||
"time-span": "^3.0.0", | ||
"tsd-check": "^0.5.0", | ||
"xo": "^0.24.0" | ||
} | ||
} |
@@ -13,3 +13,3 @@ # p-min-delay [![Build Status](https://travis-ci.org/sindresorhus/p-min-delay.svg?branch=master)](https://travis-ci.org/sindresorhus/p-min-delay) | ||
``` | ||
$ npm install --save p-min-delay | ||
$ npm install p-min-delay | ||
``` | ||
@@ -23,5 +23,6 @@ | ||
pMinDelay(somePromise, 1000).then(value => { | ||
// executed after minimum 1 second even if `somePromise` fulfills before that | ||
}); | ||
(async () => { | ||
const value = await pMinDelay(somePromise, 1000); | ||
// Executed after minimum 1 second even if `somePromise` fulfills before that | ||
})(); | ||
``` | ||
@@ -32,5 +33,5 @@ | ||
### pMinDelay(input, minimumDelay, [options]) | ||
### pMinDelay(promise, minimumDelay, [options]) | ||
#### input | ||
#### promise | ||
@@ -37,0 +38,0 @@ Type: `Promise` |
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
4831
5
44
70
5
+ Addeddelay@4.4.1(transitive)
- Removeddelay@1.3.1(transitive)
Updateddelay@^4.1.0