Galerie und tage
This commit is contained in:
77
node_modules/p-cancelable/index.js
generated
vendored
77
node_modules/p-cancelable/index.js
generated
vendored
@@ -1,77 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
class CancelError extends Error {
|
||||
constructor() {
|
||||
super('Promise was canceled');
|
||||
this.name = 'CancelError';
|
||||
}
|
||||
}
|
||||
|
||||
class PCancelable {
|
||||
static fn(fn) {
|
||||
return function () {
|
||||
const args = [].slice.apply(arguments);
|
||||
return new PCancelable((onCancel, resolve, reject) => {
|
||||
args.unshift(onCancel);
|
||||
fn.apply(null, args).then(resolve, reject);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
constructor(executor) {
|
||||
this._pending = true;
|
||||
this._canceled = false;
|
||||
|
||||
this._promise = new Promise((resolve, reject) => {
|
||||
this._reject = reject;
|
||||
|
||||
return executor(
|
||||
fn => {
|
||||
this._cancel = fn;
|
||||
},
|
||||
val => {
|
||||
this._pending = false;
|
||||
resolve(val);
|
||||
},
|
||||
err => {
|
||||
this._pending = false;
|
||||
reject(err);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
then() {
|
||||
return this._promise.then.apply(this._promise, arguments);
|
||||
}
|
||||
|
||||
catch() {
|
||||
return this._promise.catch.apply(this._promise, arguments);
|
||||
}
|
||||
|
||||
cancel() {
|
||||
if (!this._pending || this._canceled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof this._cancel === 'function') {
|
||||
try {
|
||||
this._cancel();
|
||||
} catch (err) {
|
||||
this._reject(err);
|
||||
}
|
||||
}
|
||||
|
||||
this._canceled = true;
|
||||
this._reject(new CancelError());
|
||||
}
|
||||
|
||||
get canceled() {
|
||||
return this._canceled;
|
||||
}
|
||||
}
|
||||
|
||||
Object.setPrototypeOf(PCancelable.prototype, Promise.prototype);
|
||||
|
||||
module.exports = PCancelable;
|
||||
module.exports.CancelError = CancelError;
|
||||
21
node_modules/p-cancelable/license
generated
vendored
21
node_modules/p-cancelable/license
generated
vendored
@@ -1,21 +0,0 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
78
node_modules/p-cancelable/package.json
generated
vendored
78
node_modules/p-cancelable/package.json
generated
vendored
@@ -1,78 +0,0 @@
|
||||
{
|
||||
"_from": "p-cancelable@^0.3.0",
|
||||
"_id": "p-cancelable@0.3.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-RVbZPLso8+jFeq1MfNvgXtCRED2raz/dKpacfTNxsx6pLEpEomM7gah6VeHSYV3+vo0OAi4MkArtQcWWXuQoyw==",
|
||||
"_location": "/p-cancelable",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "p-cancelable@^0.3.0",
|
||||
"name": "p-cancelable",
|
||||
"escapedName": "p-cancelable",
|
||||
"rawSpec": "^0.3.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^0.3.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/got"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-0.3.0.tgz",
|
||||
"_shasum": "b9e123800bcebb7ac13a479be195b507b98d30fa",
|
||||
"_spec": "p-cancelable@^0.3.0",
|
||||
"_where": "/var/www/html/jason/WeihnachtenMelly/node_modules/got",
|
||||
"author": {
|
||||
"name": "Sindre Sorhus",
|
||||
"email": "sindresorhus@gmail.com",
|
||||
"url": "sindresorhus.com"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/sindresorhus/p-cancelable/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"deprecated": false,
|
||||
"description": "Create a promise that can be canceled",
|
||||
"devDependencies": {
|
||||
"ava": "*",
|
||||
"delay": "^2.0.0",
|
||||
"xo": "*"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=4"
|
||||
},
|
||||
"files": [
|
||||
"index.js"
|
||||
],
|
||||
"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",
|
||||
"name": "p-cancelable",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/sindresorhus/p-cancelable.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "xo && ava"
|
||||
},
|
||||
"version": "0.3.0"
|
||||
}
|
||||
132
node_modules/p-cancelable/readme.md
generated
vendored
132
node_modules/p-cancelable/readme.md
generated
vendored
@@ -1,132 +0,0 @@
|
||||
# p-cancelable [](https://travis-ci.org/sindresorhus/p-cancelable)
|
||||
|
||||
> Create a promise that can be canceled
|
||||
|
||||
Useful for animation, loading resources, long-running async computations, async iteration, etc.
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install --save p-cancelable
|
||||
```
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
const PCancelable = require('p-cancelable');
|
||||
|
||||
const cancelablePromise = new PCancelable((onCancel, resolve, reject) => {
|
||||
const worker = new SomeLongRunningOperation();
|
||||
|
||||
onCancel(() => {
|
||||
worker.close();
|
||||
});
|
||||
|
||||
worker.on('finish', resolve);
|
||||
worker.on('error', reject);
|
||||
});
|
||||
|
||||
cancelablePromise
|
||||
.then(value => {
|
||||
console.log('Operation finished successfully:', value);
|
||||
})
|
||||
.catch(reason => {
|
||||
if (cancelablePromise.canceled) {
|
||||
// Handle the cancelation here
|
||||
console.log('Operation was canceled');
|
||||
return;
|
||||
}
|
||||
|
||||
throw reason;
|
||||
});
|
||||
|
||||
// Cancel the operation after 10 seconds
|
||||
setTimeout(() => {
|
||||
cancelablePromise.cancel();
|
||||
}, 10000);
|
||||
```
|
||||
|
||||
|
||||
## API
|
||||
|
||||
### new PCancelable(executor)
|
||||
|
||||
Same as the [`Promise` constructor](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Promise), but with a prepended `onCancel` parameter in `executor`.
|
||||
|
||||
`PCancelable` is a subclass of `Promise`.
|
||||
|
||||
#### onCanceled(fn)
|
||||
|
||||
Type: `Function`
|
||||
|
||||
Accepts a function that is called when the promise is canceled.
|
||||
|
||||
You're not required to call this function.
|
||||
|
||||
### PCancelable#cancel()
|
||||
|
||||
Type: `Function`
|
||||
|
||||
Cancel the promise. The cancellation is synchronous.
|
||||
|
||||
Calling it after the promise has settled or multiple times does nothing.
|
||||
|
||||
### PCancelable#canceled
|
||||
|
||||
Type: `boolean`
|
||||
|
||||
Whether the promise is canceled.
|
||||
|
||||
### PCancelable.CancelError
|
||||
|
||||
Type: `Error`
|
||||
|
||||
Rejection reason when `.cancel()` is called.
|
||||
|
||||
### PCancelable.fn(fn)
|
||||
|
||||
Convenience method to make your promise-returning or async function cancelable.
|
||||
|
||||
The function you specify will have `onCancel` prepended to its parameters.
|
||||
|
||||
```js
|
||||
const fn = PCancelable.fn((onCancel, input) => {
|
||||
const job = new Job();
|
||||
|
||||
onCancel(() => {
|
||||
job.cleanup();
|
||||
});
|
||||
|
||||
return job.start(); //=> Promise
|
||||
});
|
||||
|
||||
const promise = fn('input'); //=> PCancelable
|
||||
|
||||
// …
|
||||
|
||||
promise.cancel();
|
||||
```
|
||||
|
||||
|
||||
## FAQ
|
||||
|
||||
### Cancelable vs. Cancellable
|
||||
|
||||
[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.
|
||||
|
||||
### What about the official [Cancelable Promises proposal](https://github.com/tc39/proposal-cancelable-promises)?
|
||||
|
||||
~~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.
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [p-lazy](https://github.com/sindresorhus/p-lazy) - Create a lazy promise that defers execution until `.then()` or `.catch()` is called
|
||||
- [More…](https://github.com/sindresorhus/promise-fun)
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
||||
Reference in New Issue
Block a user