commit
This commit is contained in:
parent
a70448a434
commit
a15c733e45
55 changed files with 13236 additions and 1 deletions
44
node_modules/bluebird/js/main/method.js
generated
vendored
Normal file
44
node_modules/bluebird/js/main/method.js
generated
vendored
Normal file
|
@ -0,0 +1,44 @@
|
|||
"use strict";
|
||||
module.exports =
|
||||
function(Promise, INTERNAL, tryConvertToPromise, apiRejection) {
|
||||
var util = require("./util.js");
|
||||
var tryCatch = util.tryCatch;
|
||||
|
||||
Promise.method = function (fn) {
|
||||
if (typeof fn !== "function") {
|
||||
throw new Promise.TypeError("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
|
||||
}
|
||||
return function () {
|
||||
var ret = new Promise(INTERNAL);
|
||||
ret._captureStackTrace();
|
||||
ret._pushContext();
|
||||
var value = tryCatch(fn).apply(this, arguments);
|
||||
ret._popContext();
|
||||
ret._resolveFromSyncValue(value);
|
||||
return ret;
|
||||
};
|
||||
};
|
||||
|
||||
Promise.attempt = Promise["try"] = function (fn, args, ctx) {
|
||||
if (typeof fn !== "function") {
|
||||
return apiRejection("fn must be a function\u000a\u000a See http://goo.gl/916lJJ\u000a");
|
||||
}
|
||||
var ret = new Promise(INTERNAL);
|
||||
ret._captureStackTrace();
|
||||
ret._pushContext();
|
||||
var value = util.isArray(args)
|
||||
? tryCatch(fn).apply(ctx, args)
|
||||
: tryCatch(fn).call(ctx, args);
|
||||
ret._popContext();
|
||||
ret._resolveFromSyncValue(value);
|
||||
return ret;
|
||||
};
|
||||
|
||||
Promise.prototype._resolveFromSyncValue = function (value) {
|
||||
if (value === util.errorObj) {
|
||||
this._rejectCallback(value.e, false, true);
|
||||
} else {
|
||||
this._resolveCallback(value, true);
|
||||
}
|
||||
};
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue