@zkochan/pnpm
Version:
Fast, disk space efficient package manager
120 lines (119 loc) • 6.61 kB
JSON
{
"_args": [
[
{
"raw": "p-cancelable@^0.4.0",
"scope": null,
"escapedName": "p-cancelable",
"name": "p-cancelable",
"rawSpec": "^0.4.0",
"spec": ">=0.4.0 <0.5.0",
"type": "range"
},
"/home/zkochan/src/pnpm/packages/pnpm/node_modules/got"
]
],
"_from": "p-cancelable@^0.4.0",
"_hasShrinkwrap": false,
"_id": "p-cancelable@0.4.1",
"_location": "/p-cancelable",
"_nodeVersion": "8.10.0",
"_npmOperationalInternal": {
"host": "s3://npm-registry-packages",
"tmp": "tmp/p-cancelable_0.4.1_1522581779099_0.05425666370241489"
},
"_npmUser": {
"name": "sindresorhus",
"email": "sindresorhus@gmail.com"
},
"_npmVersion": "5.6.0",
"_phantomChildren": {},
"_requested": {
"raw": "p-cancelable@^0.4.0",
"scope": null,
"escapedName": "p-cancelable",
"name": "p-cancelable",
"rawSpec": "^0.4.0",
"spec": ">=0.4.0 <0.5.0",
"type": "range"
},
"_requiredBy": [
"/got"
],
"_resolved": "http://registry.npmjs.org/p-cancelable/-/p-cancelable-0.4.1.tgz",
"_shasum": "35f363d67d52081c8d9585e37bcceb7e0bbcb2a0",
"_shrinkwrap": null,
"_spec": "p-cancelable@^0.4.0",
"_where": "/home/zkochan/src/pnpm/packages/pnpm/node_modules/got",
"author": {
"name": "Sindre Sorhus",
"email": "sindresorhus@gmail.com",
"url": "sindresorhus.com"
},
"bugs": {
"url": "https://github.com/sindresorhus/p-cancelable/issues"
},
"dependencies": {},
"description": "Create a promise that can be canceled",
"devDependencies": {
"ava": "*",
"delay": "^2.0.0",
"promise.prototype.finally": "^3.1.0",
"xo": "*"
},
"directories": {},
"dist": {
"integrity": "sha512-HNa1A8LvB1kie7cERyy21VNeHb2CWJJYqyyC2o3klWFfMGlFmWv2Z7sFgZH8ZiaYL95ydToKTFVXgMV/Os0bBQ==",
"shasum": "35f363d67d52081c8d9585e37bcceb7e0bbcb2a0",
"tarball": "http://registry.npmjs.org/p-cancelable/-/p-cancelable-0.4.1.tgz",
"fileCount": 4,
"unpackedSize": 6976
},
"engines": {
"node": ">=4"
},
"files": [
"index.js"
],
"gitHead": "50d66ce7228c23511a754a03d52aebf55e0229b1",
"homepage": "https://github.com/sindresorhus/p-cancelable#readme",
"keywords": [
"promise",
"cancelable",
"cancel",
"canceled",
"canceling",
"cancellable",
"cancellation",
"abort",
"abortable",
"aborting",
"cleanup",
"task",
"token",
"async",
"function",
"await",
"promises",
"bluebird"
],
"license": "MIT",
"maintainers": [
{
"name": "sindresorhus",
"email": "sindresorhus@gmail.com"
}
],
"name": "p-cancelable",
"optionalDependencies": {},
"readme": "# p-cancelable [](https://travis-ci.org/sindresorhus/p-cancelable)\n\n> Create a promise that can be canceled\n\nUseful for animation, loading resources, long-running async computations, async iteration, etc.\n\n\n## Install\n\n```\n$ npm install p-cancelable\n```\n\n\n## Usage\n\n```js\nconst PCancelable = require('p-cancelable');\n\nconst cancelablePromise = new PCancelable((resolve, reject, onCancel) => {\n\tconst worker = new SomeLongRunningOperation();\n\n\tonCancel(() => {\n\t\tworker.close();\n\t});\n\n\tworker.on('finish', resolve);\n\tworker.on('error', reject);\n});\n\ncancelablePromise\n\t.then(value => {\n\t\tconsole.log('Operation finished successfully:', value);\n\t})\n\t.catch(error => {\n\t\tif (cancelablePromise.isCanceled) {\n\t\t\t// Handle the cancelation here\n\t\t\tconsole.log('Operation was canceled');\n\t\t\treturn;\n\t\t}\n\n\t\tthrow error;\n\t});\n\n// Cancel the operation after 10 seconds\nsetTimeout(() => {\n\tcancelablePromise.cancel();\n}, 10000);\n```\n\n\n## API\n\n### new PCancelable(executor)\n\nSame as the [`Promise` constructor](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise), but with an appended `onCancel` parameter in `executor`.\n\n`PCancelable` is a subclass of `Promise`.\n\n#### onCanceled(fn)\n\nType: `Function`\n\nAccepts a function that is called when the promise is canceled.\n\nYou're not required to call this function. You can call this function multiple times to add multiple cancel handlers.\n\n### PCancelable#cancel()\n\nType: `Function`\n\nCancel the promise.\n\nThe cancellation is synchronous. Calling it after the promise has settled or multiple times does nothing.\n\n### PCancelable#isCanceled\n\nType: `boolean`\n\nWhether the promise is canceled.\n\n### PCancelable.CancelError\n\nType: `Error`\n\nRejection reason when `.cancel()` is called.\n\nIt includes a `.isCanceled` property for convenience.\n\n### PCancelable.fn(fn)\n\nConvenience method to make your promise-returning or async function cancelable.\n\nThe function you specify will have `onCancel` appended to its parameters.\n\n```js\nconst fn = PCancelable.fn((input, onCancel) => {\n\tconst job = new Job();\n\n\tonCancel(() => {\n\t\tjob.cleanup();\n\t});\n\n\treturn job.start(); //=> Promise\n});\n\nconst promise = fn('input'); //=> PCancelable\n\n// …\n\npromise.cancel();\n```\n\n\n## FAQ\n\n### Cancelable vs. Cancellable\n\n[In American English, the verb cancel is usually inflected canceled and canceling—with one l.](http://grammarist.com/spelling/cancel/)<br>Both a [browser API](https://developer.mozilla.org/en-US/docs/Web/API/Event/cancelable) and the [Cancelable Promises proposal](https://github.com/tc39/proposal-cancelable-promises) use this spelling.\n\n### What about the official [Cancelable Promises proposal](https://github.com/tc39/proposal-cancelable-promises)?\n\n~~It's still an early draft and I don't really like its current direction. It complicates everything and will require deep changes in the ecosystem to adapt to it. And the way you have to use cancel tokens is verbose and convoluted. I much prefer the more pragmatic and less invasive approach in this module.~~ The proposal was withdrawn.\n\n\n## Related\n\n- [p-progress](https://github.com/sindresorhus/p-progress) - Create a promise that reports progress\n- [p-lazy](https://github.com/sindresorhus/p-lazy) - Create a lazy promise that defers execution until `.then()` or `.catch()` is called\n- [More…](https://github.com/sindresorhus/promise-fun)\n\n\n## License\n\nMIT © [Sindre Sorhus](https://sindresorhus.com)\n",
"readmeFilename": "readme.md",
"repository": {
"type": "git",
"url": "git+https://github.com/sindresorhus/p-cancelable.git"
},
"scripts": {
"test": "xo && ava"
},
"version": "0.4.1"
}