promise-poller
Advanced tools
Comparing version 1.7.0 to 1.8.0
@@ -8,4 +8,2 @@ "use strict"; | ||
var _bluebird = _interopRequireDefault(require("bluebird")); | ||
var _debug = _interopRequireDefault(require("debug")); | ||
@@ -15,5 +13,7 @@ | ||
var _util = require("./util"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var debug = (0, _debug.default)('promisePoller'); | ||
var debugMessage = (0, _debug.default)('promisePoller'); | ||
var DEFAULTS = { | ||
@@ -31,2 +31,6 @@ strategy: 'fixed-interval', | ||
function debug(message) { | ||
debugMessage("(".concat(options.name, "): ").concat(message)); | ||
} | ||
if (typeof options.taskFn !== 'function') { | ||
@@ -36,5 +40,3 @@ throw new Error('No taskFn function specified in options'); | ||
Object.keys(DEFAULTS).forEach(function (option) { | ||
return options[option] = options[option] || DEFAULTS[option]; | ||
}); | ||
options = Object.assign({}, DEFAULTS, options); | ||
options.name = options.name || "Poller-".concat(pollerCount++); | ||
@@ -48,3 +50,3 @@ debug("Creating a promise poller \"".concat(options.name, "\" with interval=").concat(options.interval, ", retries=").concat(options.retries)); | ||
var strategy = _strategies.default[options.strategy]; | ||
debug("(".concat(options.name, ") Using strategy \"").concat(options.strategy, "\".")); | ||
debug("Using strategy \"".concat(options.strategy, "\".")); | ||
var strategyDefaults = strategy.defaults; | ||
@@ -54,7 +56,7 @@ Object.keys(strategyDefaults).forEach(function (option) { | ||
}); | ||
debug("(".concat(options.name, ") Options:")); | ||
debug('Options:'); | ||
Object.keys(options).forEach(function (option) { | ||
debug(" \"".concat(option, "\": ").concat(options[option])); | ||
}); | ||
return new _bluebird.default(function (resolve, reject) { | ||
return new Promise(function (resolve, reject) { | ||
var polling = true; | ||
@@ -66,5 +68,5 @@ var retriesRemaining = options.retries; | ||
if (options.masterTimeout) { | ||
debug("(".concat(options.name, ") Using master timeout of ").concat(options.masterTimeout, " ms.")); | ||
debug("Using master timeout of ".concat(options.masterTimeout, " ms.")); | ||
timeoutId = setTimeout(function () { | ||
debug("(".concat(options.name, ") Master timeout reached. Rejecting master promise.")); | ||
debug('Master timeout reached. Rejecting master promise.'); | ||
polling = false; | ||
@@ -79,4 +81,4 @@ reject('master timeout'); | ||
if (task === false) { | ||
task = _bluebird.default.reject('Cancelled'); | ||
debug("(".concat(options.name, ") Task function returned false, canceling.")); | ||
task = Promise.reject('Cancelled'); | ||
debug('Task function returned false, canceling.'); | ||
reject(rejections); | ||
@@ -86,17 +88,16 @@ polling = false; | ||
var taskPromise = _bluebird.default.resolve(task); | ||
var taskPromise = Promise.resolve(task); | ||
if (options.timeout) { | ||
taskPromise = taskPromise.timeout(options.timeout); | ||
taskPromise = (0, _util.timeout)(taskPromise, options.timeout); | ||
} | ||
taskPromise.then(function (result) { | ||
debug("(".concat(options.name, ") Poll succeeded. Resolving master promise.")); | ||
debug('Poll succeeded. Resolving master promise.'); | ||
if (options.shouldContinue(null, result)) { | ||
debug("(".concat(options.name, ") shouldContinue returned true. Retrying.")); | ||
debug('shouldContinue returned true. Retrying.'); | ||
var nextInterval = strategy.getNextInterval(options.retries - retriesRemaining, options); | ||
debug("(".concat(options.name, ") Waiting ").concat(nextInterval, "ms to try again.")); | ||
_bluebird.default.delay(nextInterval).then(poll); | ||
debug("Waiting ".concat(nextInterval, "ms to try again.")); | ||
(0, _util.delay)(nextInterval).then(poll); | ||
} else { | ||
@@ -117,10 +118,9 @@ if (timeoutId !== null) { | ||
if (! --retriesRemaining || !options.shouldContinue(err)) { | ||
debug("(".concat(options.name, ") Maximum retries reached. Rejecting master promise.")); | ||
debug('Maximum retries reached. Rejecting master promise.'); | ||
reject(rejections); | ||
} else if (polling) { | ||
debug("(".concat(options.name, ") Poll failed. ").concat(retriesRemaining, " retries remaining.")); | ||
debug("Poll failed. ".concat(retriesRemaining, " retries remaining.")); | ||
var nextInterval = strategy.getNextInterval(options.retries - retriesRemaining, options); | ||
debug("(".concat(options.name, ") Waiting ").concat(nextInterval, "ms to try again.")); | ||
_bluebird.default.delay(nextInterval).then(poll); | ||
debug("Waiting ".concat(nextInterval, "ms to try again.")); | ||
(0, _util.delay)(nextInterval).then(poll); | ||
} | ||
@@ -127,0 +127,0 @@ }); |
@@ -5,4 +5,2 @@ "use strict"; | ||
var _bluebird = _interopRequireDefault(require("bluebird")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -16,3 +14,3 @@ | ||
taskFn: function taskFn() { | ||
return _bluebird.default.resolve('yay'); | ||
return Promise.resolve('yay'); | ||
} | ||
@@ -26,3 +24,3 @@ }); | ||
taskFn: function taskFn() { | ||
return _bluebird.default.resolve('yay'); | ||
return Promise.resolve('yay'); | ||
}, | ||
@@ -41,3 +39,3 @@ interval: 500, | ||
taskFn: function taskFn() { | ||
return _bluebird.default.reject('derp'); | ||
return Promise.reject('derp'); | ||
}, | ||
@@ -48,5 +46,3 @@ interval: 500, | ||
return fail('Promise was resolved'); | ||
}, function () { | ||
done(); | ||
}); | ||
}, done); | ||
}); | ||
@@ -57,3 +53,3 @@ it('rejects the master promise with an array of rejections', function (done) { | ||
taskFn: function taskFn() { | ||
return _bluebird.default.reject(++counter); | ||
return Promise.reject(++counter); | ||
}, | ||
@@ -71,3 +67,3 @@ interval: 500, | ||
var taskFn = function taskFn() { | ||
return new _bluebird.default(function (resolve) { | ||
return new Promise(function (resolve) { | ||
setTimeout(function () { | ||
@@ -96,3 +92,3 @@ return resolve('derp'); | ||
var taskFn = function taskFn() { | ||
return new _bluebird.default(function (resolve, reject) { | ||
return new Promise(function (resolve, reject) { | ||
numPolls += 1; | ||
@@ -129,3 +125,3 @@ setTimeout(function () { | ||
last = now; | ||
return _bluebird.default.reject('derp'); | ||
return Promise.reject('derp'); | ||
}; | ||
@@ -144,3 +140,3 @@ | ||
counter++; | ||
return _bluebird.default.reject('derp'); | ||
return Promise.reject('derp'); | ||
}; | ||
@@ -161,3 +157,3 @@ | ||
counter++; | ||
return _bluebird.default.reject('derp'); | ||
return Promise.reject('derp'); | ||
}; | ||
@@ -186,3 +182,3 @@ | ||
last = now; | ||
return _bluebird.default.reject('derp'); | ||
return Promise.reject('derp'); | ||
}; | ||
@@ -213,3 +209,3 @@ | ||
taskFn: function taskFn() { | ||
return _bluebird.default.reject('derp'); | ||
return Promise.reject('derp'); | ||
}, | ||
@@ -255,3 +251,3 @@ interval: 500, | ||
} else { | ||
return _bluebird.default.reject('derp'); | ||
return Promise.reject('derp'); | ||
} | ||
@@ -278,3 +274,3 @@ }; | ||
taskFn: function taskFn() { | ||
return _bluebird.default.resolve('foobar'); | ||
return Promise.resolve('foobar'); | ||
}, | ||
@@ -293,3 +289,3 @@ masterTimeout: 10000 | ||
var taskFn = function taskFn() { | ||
return _bluebird.default.reject(++counter); | ||
return Promise.reject(++counter); | ||
}; | ||
@@ -313,3 +309,3 @@ | ||
var taskFn = function taskFn() { | ||
return _bluebird.default.resolve(++counter); | ||
return Promise.resolve(++counter); | ||
}; | ||
@@ -316,0 +312,0 @@ |
{ | ||
"name": "promise-poller", | ||
"version": "1.7.0", | ||
"version": "1.8.0", | ||
"description": "A basic poller built on top of promises", | ||
@@ -46,3 +46,2 @@ "main": "dist/lib/promise-poller.js", | ||
"dependencies": { | ||
"bluebird": "^3.5.3", | ||
"debug": "^4.1.0" | ||
@@ -49,0 +48,0 @@ }, |
@@ -6,3 +6,3 @@ # promise-poller | ||
A basic poller built on top of promises. You can use any promise library that is Promises/A+ compliant. | ||
A basic poller built on top of promises. | ||
@@ -128,3 +128,3 @@ Sometimes, you may perform asynchronous operations that may fail. In many of those cases, you want to retry these operations one or more times before giving up. `promise-poller` handles this elegantly using promises. | ||
name: 'App Server Poller' | ||
)}; | ||
}); | ||
@@ -131,0 +131,0 @@ When this poller prints debug messages, the poller name will be included: |
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
1
14
494
27287
- Removedbluebird@^3.5.3
- Removedbluebird@3.7.2(transitive)