Skip to content

Commit cdbeccc

Browse files
committed
enable synchronous inspection
1 parent 8a42572 commit cdbeccc

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ require('./done.js');
55
require('./finally.js');
66
require('./es6-extensions.js');
77
require('./node-extensions.js');
8+
require('./synchronous.js');

src/synchronous.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'use strict';
2+
3+
var Promise = require('./core.js');
4+
5+
module.exports = Promise;
6+
Promise.enableSynchronous = function () {
7+
Promise.prototype.isPending = function() {
8+
return this._state == 0;
9+
};
10+
11+
Promise.prototype.isFulfilled = function() {
12+
return this._state == 1;
13+
};
14+
15+
Promise.prototype.isRejected = function() {
16+
return this._state == 2;
17+
};
18+
19+
Promise.prototype.value = function () {
20+
if (!this.isFulfilled()) {
21+
throw new Error('Cannot get a value of an unfulfilled promise.');
22+
}
23+
24+
return this._value;
25+
};
26+
27+
Promise.prototype.reason = function () {
28+
if (!this.isRejected()) {
29+
throw new Error('Cannot get a rejection reason of a non-rejected promise.');
30+
}
31+
32+
return this._value;
33+
};
34+
};

0 commit comments

Comments
 (0)