commit
This commit is contained in:
parent
a70448a434
commit
a15c733e45
55 changed files with 13236 additions and 1 deletions
48
node_modules/bluebird/js/main/cancel.js
generated
vendored
Normal file
48
node_modules/bluebird/js/main/cancel.js
generated
vendored
Normal file
|
@ -0,0 +1,48 @@
|
|||
"use strict";
|
||||
module.exports = function(Promise) {
|
||||
var errors = require("./errors.js");
|
||||
var async = require("./async.js");
|
||||
var CancellationError = errors.CancellationError;
|
||||
|
||||
Promise.prototype._cancel = function (reason) {
|
||||
if (!this.isCancellable()) return this;
|
||||
var parent;
|
||||
var promiseToReject = this;
|
||||
while ((parent = promiseToReject._cancellationParent) !== undefined &&
|
||||
parent.isCancellable()) {
|
||||
promiseToReject = parent;
|
||||
}
|
||||
this._unsetCancellable();
|
||||
promiseToReject._target()._rejectCallback(reason, false, true);
|
||||
};
|
||||
|
||||
Promise.prototype.cancel = function (reason) {
|
||||
if (!this.isCancellable()) return this;
|
||||
if (reason === undefined) reason = new CancellationError();
|
||||
async.invokeLater(this._cancel, this, reason);
|
||||
return this;
|
||||
};
|
||||
|
||||
Promise.prototype.cancellable = function () {
|
||||
if (this._cancellable()) return this;
|
||||
async.enableTrampoline();
|
||||
this._setCancellable();
|
||||
this._cancellationParent = undefined;
|
||||
return this;
|
||||
};
|
||||
|
||||
Promise.prototype.uncancellable = function () {
|
||||
var ret = this.then();
|
||||
ret._unsetCancellable();
|
||||
return ret;
|
||||
};
|
||||
|
||||
Promise.prototype.fork = function (didFulfill, didReject, didProgress) {
|
||||
var ret = this._then(didFulfill, didReject, didProgress,
|
||||
undefined, undefined);
|
||||
|
||||
ret._setCancellable();
|
||||
ret._cancellationParent = undefined;
|
||||
return ret;
|
||||
};
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue