promise-delay
Advanced tools
Comparing version 2.0.0 to 2.1.0
@@ -13,2 +13,11 @@ if (!global.Promise) { | ||
function delayedReject (delay, val) { | ||
return new Promise(function (resolve, reject) { | ||
setTimeout(function () { | ||
reject(val) | ||
}, delay) | ||
}) | ||
} | ||
module.exports = promiseDelay | ||
module.exports.reject = delayedReject |
{ | ||
"name": "promise-delay", | ||
"author": "jden <jason@denizac.org>", | ||
"version": "2.0.0", | ||
"version": "2.1.0", | ||
"engines": { | ||
"node": ">=0.12" | ||
}, | ||
"description": "like Promise.cast with a delay in milliseconds", | ||
"description": "like Promise.resolve with a delay in milliseconds", | ||
"keywords": [ | ||
@@ -10,0 +10,0 @@ "promise", |
# promise-delay | ||
like Promise.cast with a delay in milliseconds | ||
like Promise.resolve with a delay in milliseconds | ||
@@ -14,3 +14,3 @@ [![Circle CI](https://circleci.com/gh/jden/node-promise-delay.svg?style=svg)](https://circleci.com/gh/jden/node-promise-delay) | ||
var eventually = promiseDelay(100, Promise.cast('foo')) | ||
var eventually = promiseDelay(100, Promise.resolve('foo')) | ||
@@ -27,3 +27,12 @@ eventually.then(next) | ||
}) | ||
``` | ||
or, reject after a delay: | ||
```js | ||
var rejected = promiseDelay.reject(100, new Error('rejected')) | ||
rejected.catch(function (err) { | ||
console.log(err) | ||
// Error: rejected | ||
}) | ||
``` | ||
@@ -30,0 +39,0 @@ |
@@ -27,2 +27,18 @@ /* globals describe, it */ | ||
}) | ||
describe('.reject', function () { | ||
it('rejects after a delay', function (end) { | ||
var start = Date.now() | ||
var err = new Error('blah') | ||
promiseDelay.reject(100, err) | ||
.then(function () { | ||
throw new Error('should not resolve') | ||
}, function (e) { | ||
expect(e).to.equal(err) | ||
var elapsed = Date.now() - start | ||
expect(elapsed).to.be.within(90, 110) | ||
}) | ||
.then(end, end) | ||
}) | ||
}) | ||
}) |
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
4032
7
56
60