promise-poller
Advanced tools
Comparing version 1.5.1 to 1.5.2
# Change Log | ||
## 1.5.2 (January 9, 2017) | ||
* Fixed the master timeout so that it doesn't make the program hang. Contributed by Jason Stitt. | ||
## 1.5.1 (October 6, 2016) | ||
* Fixed the master timeout so that it fires properly and no subsequent polls are made. | ||
## 1.5.0 (August 17, 2016) | ||
* Added feature to reject the master promise if the task function returns false | ||
## 1.4.0 (April 21, 2016) | ||
@@ -4,0 +15,0 @@ |
@@ -63,6 +63,7 @@ 'use strict'; | ||
var rejections = []; | ||
var timeoutId = null; | ||
if (options.masterTimeout) { | ||
debug('(' + options.name + ') Using master timeout of ' + options.masterTimeout + ' ms.'); | ||
setTimeout(function () { | ||
timeoutId = setTimeout(function () { | ||
debug('(' + options.name + ') Master timeout reached. Rejecting master promise.'); | ||
@@ -79,3 +80,5 @@ polling = false; | ||
task = _bluebird2.default.reject('Cancelled'); | ||
retriesRemaining = 1; | ||
debug('(' + options.name + ') Task function returned false, canceling.'); | ||
reject(rejections); | ||
polling = false; | ||
} | ||
@@ -91,2 +94,5 @@ | ||
debug('(' + options.name + ') Poll succeeded. Resolving master promise.'); | ||
if (timeoutId !== null) { | ||
clearTimeout(timeoutId); | ||
} | ||
resolve(result); | ||
@@ -93,0 +99,0 @@ }, function (err) { |
@@ -262,2 +262,21 @@ 'use strict'; | ||
}); | ||
it('clears the master timeout if the master promise resolves', function (done) { | ||
var globalObj = jasmine.getGlobal(); | ||
spyOn(globalObj, 'setTimeout').and.callFake(function () { | ||
return 42; | ||
}); | ||
spyOn(globalObj, 'clearTimeout'); | ||
(0, _promisePoller2.default)({ | ||
taskFn: function taskFn() { | ||
return _bluebird2.default.resolve('foobar'); | ||
}, | ||
masterTimeout: 10000 | ||
}).then(function (val) { | ||
expect(val).toEqual('foobar'); | ||
expect(globalObj.setTimeout).toHaveBeenCalled(); | ||
expect(globalObj.clearTimeout).toHaveBeenCalledWith(42); | ||
done(); | ||
}); | ||
}); | ||
}); |
{ | ||
"name": "promise-poller", | ||
"version": "1.5.1", | ||
"version": "1.5.2", | ||
"description": "A basic poller built on top of promises", | ||
@@ -35,5 +35,5 @@ "main": "dist/lib/promise-poller.js", | ||
"babel-cli": "^6.11.4", | ||
"babel-eslint": "^6.0.0", | ||
"babel-eslint": "^7.0.0", | ||
"babel-preset-es2015": "^6.5.0", | ||
"eslint": "^2.1.0", | ||
"eslint": "^3.7.1", | ||
"jasmine": "^2.4.1", | ||
@@ -40,0 +40,0 @@ "jasmine-core": "^2.4.1" |
@@ -132,2 +132,3 @@ # promise-poller | ||
* /u/jcready | ||
* Jason Stitt | ||
@@ -134,0 +135,0 @@ # License |
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
25335
441
156