promise-poller
Advanced tools
Comparing version 1.3.0 to 1.4.0
# Change Log | ||
## 1.4.0 (April 21, 2016) | ||
* Added master timeout support. | ||
## 1.3.0 (March 22, 2016) | ||
@@ -4,0 +8,0 @@ |
@@ -57,7 +57,16 @@ 'use strict'; | ||
var rejections = []; | ||
if (options.masterTimeout) { | ||
setTimeout(function () { | ||
return reject('master timeout'); | ||
}, options.globalTimeout); | ||
} | ||
function poll() { | ||
var taskPromise = _bluebird2.default.resolve(options.taskFn()); | ||
if (options.timeout) { | ||
taskPromise = taskPromise.timeout(options.timeout); | ||
} | ||
taskPromise.then(function (result) { | ||
@@ -64,0 +73,0 @@ debug('(' + options.name + ') Poll succeeded. Resolving master promise.'); |
@@ -50,3 +50,3 @@ 'use strict'; | ||
return fail('Promise was resolved'); | ||
}, function (err) { | ||
}, function () { | ||
done(); | ||
@@ -74,3 +74,3 @@ }); | ||
var taskFn = function taskFn() { | ||
return new _bluebird2.default(function (resolve, reject) { | ||
return new _bluebird2.default(function (resolve) { | ||
setTimeout(function () { | ||
@@ -96,2 +96,27 @@ return resolve('derp'); | ||
it('rejects the master promise if the master timeout is exceeded', function (done) { | ||
var numPolls = 0; | ||
var taskFn = function taskFn() { | ||
return new _bluebird2.default(function (resolve, reject) { | ||
numPolls += 1; | ||
setTimeout(function () { | ||
return reject('derp'); | ||
}, 250); | ||
}); | ||
}; | ||
(0, _promisePoller2.default)({ | ||
taskFn: taskFn, | ||
masterTimeout: 500, | ||
retries: 10 | ||
}).then(function () { | ||
fail('Master promise was resolved, should have hit master timeout'); | ||
done(); | ||
}, function () { | ||
expect(numPolls).not.toBeGreaterThan(2); | ||
done(); | ||
}); | ||
}); | ||
it('waits the given interval between attempts', function (done) { | ||
@@ -98,0 +123,0 @@ var last = 0; |
{ | ||
"name": "promise-poller", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "A basic poller built on top of promises", | ||
"main": "dist/lib/promise-poller.js", | ||
"scripts": { | ||
"prepublish": "npm run compile", | ||
"prepublish": "npm run build", | ||
"build": "npm run lint && npm test", | ||
"compile": "babel -d dist src", | ||
@@ -33,7 +34,5 @@ "clean": "rm -rf dist", | ||
"devDependencies": { | ||
"babel-eslint": "^5.0.0", | ||
"babel-eslint": "^6.0.0", | ||
"babel-preset-es2015": "^6.5.0", | ||
"eslint": "^2.1.0", | ||
"eslint-config-standard": "^5.1.0", | ||
"eslint-plugin-standard": "^1.3.2", | ||
"jasmine-core": "^2.4.1" | ||
@@ -40,0 +39,0 @@ }, |
@@ -41,3 +41,3 @@ # promise-poller | ||
## Specify timeout | ||
If you want the poll to reject after a certain timeout has passed, use the `timeout` option: | ||
If you want each poll attempt to reject after a certain timeout has passed, use the `timeout` option: | ||
@@ -50,4 +50,16 @@ var poller = promisePoller({ | ||
In the above example, the poll is considered failed if it isn't resolved after 2 seconds. | ||
In the above example, the poll is considered failed if it isn't resolved after 2 seconds. If there are retries remaining, it will retry the poll as usual. | ||
## Specify "master timeout" | ||
Instead of timing out each poll attempt, you can set a timeout for the entire master polling operation: | ||
var poller = promisePoller({ | ||
taskFn: myTask, | ||
interval: 500, | ||
retries: 10, | ||
masterTimeout: 2000 | ||
}); | ||
In the above example, the entire poll operation will fail if there is not a successful poll within 2 seconds. This will reject the master promise. | ||
## Select polling strategy | ||
@@ -54,0 +66,0 @@ By default, `promise-poller` will use a fixed interval between each poll attempt. For example, with an `interval` option of 500, the poller will poll approximately every 500 milliseconds. This is the `fixed-interval` strategy. There are two other strategies available that may better suit your use case. To select a polling strategy, specify the `strategy` option, e.g.: |
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
23103
4
400
147