Package Exports
- only-last-promise
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (only-last-promise) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
only-last-promise
Resolve or reject only last Promise.
Useful if you want to "abort" already running async operations started with debounced input event.
Install
npm install only-last-promise --saveUsage
When calling the wrapper function multiple times, only the last returned
Promise will resolve or reject and all other Promises will be aborted with
DiscardSignal error.
import onlyLastPromise, { DiscardSignal } from 'only-last-promise';
const wrapper = onlyLastPromise();
async function main() {
try {
return await wrapper(fetch('/becky'));
} catch (error) {
if (!(error instanceof DiscardSignal)) {
throw error;
}
}
}API
onlyLastPromise()
Returns: Function
Factory function which returns wrapper function.
wrapper(promise)
Type: Function
promise
Type: Promise
Promise to handle.
Browser support
Tested in IE9+ and all modern browsers.
Test
For automated tests, run npm run test:automated (append :watch for watcher
support).
License
MIT © Ivan Nikolić