@permettezmoideconstruire/cancellable-promise
v0.0.2
Published
Non intrusive Promise wrapper to make it cancellable
Downloads
569
Readme
webpack-library-starter
Non intrusive Promise wrapper to make it cancellable
Installation
npm install @permettezmoideconstruire/cancellable-promise
or include
<script src="https://unpkg.com/@permettezmoideconstruire/cancellable-promise"></script>
You can specify a npm release with
<script src="https://unpkg.com/@permettezmoideconstruire/[email protected]"></script>
Usage
// Import
import {
cancellablePromise,
CancelError,
CancelToken
} from '@permettezmoideconstruire/cancellable-promise'
// --- OR ---
const {
cancellablePromise,
CancelError,
CancelToken
} = require('@permettezmoideconstruire/cancellable-promise').default
// Wrap a promise
const initialPromise = SOMETHING_ASYNC()
const cancelToken = new CancelToken()
const wrappedPromise = cancellablePromise(initialPromise, cancelToken)
// Somewhere, cancel the promise...
cancelToken.cancel()
//Then catch it
wrappedPromise
.then((res) => {
//Actual, usual fulfill
})
.catch((err) => {
if(err instanceOf CancelError) {
//Handle cancel error
}
//Handle actual, usual error
})
Process
ES6 source files
|
|
webpack
|
+--- babel, eslint
|
ready to use
library
in umd format
Scripts
npm run compile
- produce builds for the appnpm run test
- run testsnpm run build
- compile and run testsnpm run dev
- produces development version of your library and runs a watchernpm run test:watch
- run tests in watch mode