wallet-core/node_modules/promise/setimmediate/synchronous.js

63 lines
1.4 KiB
JavaScript
Raw Normal View History

2016-10-10 03:43:44 +02:00
'use strict';
var Promise = require('./core.js');
module.exports = Promise;
Promise.enableSynchronous = function () {
Promise.prototype.isPending = function() {
return this.getState() == 0;
};
Promise.prototype.isFulfilled = function() {
return this.getState() == 1;
};
Promise.prototype.isRejected = function() {
return this.getState() == 2;
};
Promise.prototype.getValue = function () {
2017-08-14 05:01:11 +02:00
if (this._65 === 3) {
return this._55.getValue();
2016-10-10 03:43:44 +02:00
}
if (!this.isFulfilled()) {
throw new Error('Cannot get a value of an unfulfilled promise.');
}
2017-08-14 05:01:11 +02:00
return this._55;
2016-10-10 03:43:44 +02:00
};
Promise.prototype.getReason = function () {
2017-08-14 05:01:11 +02:00
if (this._65 === 3) {
return this._55.getReason();
2016-10-10 03:43:44 +02:00
}
if (!this.isRejected()) {
throw new Error('Cannot get a rejection reason of a non-rejected promise.');
}
2017-08-14 05:01:11 +02:00
return this._55;
2016-10-10 03:43:44 +02:00
};
Promise.prototype.getState = function () {
2017-08-14 05:01:11 +02:00
if (this._65 === 3) {
return this._55.getState();
2016-10-10 03:43:44 +02:00
}
2017-08-14 05:01:11 +02:00
if (this._65 === -1 || this._65 === -2) {
2016-10-10 03:43:44 +02:00
return 0;
}
2017-08-14 05:01:11 +02:00
return this._65;
2016-10-10 03:43:44 +02:00
};
};
Promise.disableSynchronous = function() {
Promise.prototype.isPending = undefined;
Promise.prototype.isFulfilled = undefined;
Promise.prototype.isRejected = undefined;
Promise.prototype.getValue = undefined;
Promise.prototype.getReason = undefined;
Promise.prototype.getState = undefined;
};