promise-poller
Advanced tools
Comparing version 1.4.1 to 1.5.0
@@ -70,4 +70,11 @@ 'use strict'; | ||
function poll() { | ||
var taskPromise = _bluebird2.default.resolve(options.taskFn()); | ||
var task = options.taskFn(); | ||
if (task === false) { | ||
task = _bluebird2.default.reject('Cancelled'); | ||
retriesRemaining = 1; | ||
} | ||
var taskPromise = _bluebird2.default.resolve(task); | ||
if (options.timeout) { | ||
@@ -74,0 +81,0 @@ taskPromise = taskPromise.timeout(options.timeout); |
@@ -241,2 +241,23 @@ 'use strict'; | ||
}); | ||
it('rejects the master promise if false is returned from the task function', function (done) { | ||
var counter = 0; | ||
var taskFn = function taskFn() { | ||
if (++counter === 1) { | ||
return false; | ||
} else { | ||
return _bluebird2.default.reject('derp'); | ||
} | ||
}; | ||
(0, _promisePoller2.default)({ | ||
taskFn: taskFn, | ||
interval: 500, | ||
retries: 3 | ||
}).then(fail, function (err) { | ||
expect(err).toEqual(['Cancelled']); | ||
expect(counter).toEqual(1); | ||
done(); | ||
}); | ||
}); | ||
}); |
{ | ||
"name": "promise-poller", | ||
"version": "1.4.1", | ||
"version": "1.5.0", | ||
"description": "A basic poller built on top of promises", | ||
@@ -34,5 +34,7 @@ "main": "dist/lib/promise-poller.js", | ||
"devDependencies": { | ||
"babel-cli": "^6.11.4", | ||
"babel-eslint": "^6.0.0", | ||
"babel-preset-es2015": "^6.5.0", | ||
"eslint": "^2.1.0", | ||
"jasmine": "^2.4.1", | ||
"jasmine-core": "^2.4.1" | ||
@@ -39,0 +41,0 @@ }, |
@@ -68,2 +68,5 @@ # promise-poller | ||
## Cancel polling | ||
You may want to cancel the polling early. For example, if the poll fails because of an invalid password, that's not likely to change, so it would be a waste of time to continue to poll. To cancel polling early, return `false` from the task function instead of a promise. | ||
## Select polling strategy | ||
@@ -70,0 +73,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
23908
413
155
6