promise-poller
Advanced tools
Comparing version 1.8.0 to 1.9.0
# Change Log | ||
## 1.9.0 (September 20, 2019) | ||
* Added async cancellation via `CANCEL_TOKEN`. | ||
## 1.8.0 (September 20, 2019) | ||
* Removed the dependency on Bluebird. The global `Promise` object is used instead. | ||
## 1.7.0 (November 17, 2018) | ||
* Fixed some broken tests. | ||
* Added Prettier. | ||
* Updated dependencies. | ||
## 1.6.0 (October 12, 2017) | ||
* Added support for the `showContinue` function. | ||
## 1.5.2 (January 9, 2017) | ||
@@ -3,0 +22,0 @@ |
@@ -7,2 +7,3 @@ "use strict"; | ||
exports.default = promisePoller; | ||
exports.CANCEL_TOKEN = void 0; | ||
@@ -26,2 +27,4 @@ var _debug = _interopRequireDefault(require("debug")); | ||
var pollerCount = 0; | ||
var CANCEL_TOKEN = {}; | ||
exports.CANCEL_TOKEN = CANCEL_TOKEN; | ||
@@ -104,2 +107,8 @@ function promisePoller() { | ||
}, function (err) { | ||
if (err === CANCEL_TOKEN) { | ||
debug('Task promise rejected with CANCEL_TOKEN, canceling.'); | ||
reject(rejections); | ||
polling = false; | ||
} | ||
rejections.push(err); | ||
@@ -106,0 +115,0 @@ |
"use strict"; | ||
var _promisePoller = _interopRequireDefault(require("../lib/promise-poller")); | ||
var _promisePoller = _interopRequireWildcard(require("../lib/promise-poller")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } | ||
@@ -252,2 +252,23 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
}); | ||
it('rejects the master promise if the task promise rejects with the cancel token', function (done) { | ||
var counter = 0; | ||
var taskFn = function taskFn() { | ||
if (++counter === 1) { | ||
return Promise.reject(_promisePoller.CANCEL_TOKEN); | ||
} else { | ||
return Promise.reject('derp'); | ||
} | ||
}; | ||
(0, _promisePoller.default)({ | ||
taskFn: taskFn, | ||
interval: 500, | ||
retries: 3 | ||
}).then(fail, function (err) { | ||
expect(err).toEqual([_promisePoller.CANCEL_TOKEN]); | ||
expect(counter).toEqual(1); | ||
done(); | ||
}); | ||
}); | ||
it('clears the master timeout if the master promise resolves', function (done) { | ||
@@ -254,0 +275,0 @@ var globalObj = jasmine.getGlobal(); |
{ | ||
"name": "promise-poller", | ||
"version": "1.8.0", | ||
"version": "1.9.0", | ||
"description": "A basic poller built on top of promises", | ||
@@ -27,3 +27,3 @@ "main": "dist/lib/promise-poller.js", | ||
], | ||
"author": "Joe Attardi <joe@attardi.net> (http://www.thinksincode.com/)", | ||
"author": "Joe Attardi <jattardi@gmail.com> (https://joeattardi.codes/)", | ||
"license": "MIT", | ||
@@ -30,0 +30,0 @@ "bugs": { |
@@ -71,2 +71,22 @@ # promise-poller | ||
Alternatively, if your task function involves async work with promises, you can reject the promise with the `CANCEL_TOKEN` object. | ||
### Cancellation example | ||
```javascript | ||
import promisePoller, { CANCEL_TOKEN } from 'promise-poller'; | ||
const taskFn = () => { | ||
return new Promise((resolve, reject) => { | ||
doAsyncStuff.then(resolve, error => { | ||
if (error === 'invalid password') { | ||
reject(CANCEL_TOKEN); // will cancel polling | ||
} else { | ||
reject(error); // will continue polling | ||
} | ||
}); | ||
}); | ||
} | ||
``` | ||
## The `shouldContinue` function | ||
@@ -138,2 +158,3 @@ You can specify an optional `shouldContinue` function that takes two arguments. The first argument is a rejection reason when a poll fails, and the second argument is the resolved value when a poll succeeds. | ||
* Jason Stitt | ||
* Emily Marigold Klassen | ||
@@ -143,3 +164,3 @@ # License | ||
Copyright (c) 2016 Joe Attardi <joe@attardi.net> | ||
Copyright (c) 2016-2019 Joe Attardi <jattardi@gmail.com> | ||
@@ -146,0 +167,0 @@ Permission is hereby granted, free of charge, to any person obtaining a copy |
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
29451
522
181