Skip to content

Commit fca9610

Browse files
committed
Change status flag on resolve/reject
1 parent d873530 commit fca9610

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

JavaScript/3-deferred.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ const deferred = () => ({
3030
},
3131
resolve(value) {
3232
this.value = value;
33+
this.status = DEFERRED_RESOLVED;
3334
if (this.onDone) this.onDone(value);
3435
return this;
3536
},
3637
reject(value) {
3738
this.value = value;
39+
this.status = DEFERRED_REJECTED;
3840
if (this.onFail) this.onFail(value);
3941
return this;
4042
}

JavaScript/4-class.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ class Deferred {
3838

3939
resolve(value) {
4040
this.value = value;
41+
this.status = DEFERRED_RESOLVED;
4142
if (this.onDone) this.onDone(value);
4243
return this;
4344
}
4445

4546
reject(value) {
4647
this.value = value;
48+
this.status = DEFERRED_REJECTED;
4749
if (this.onFail) this.onFail(value);
4850
return this;
4951
}

JavaScript/5-emitter.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ class Deferred extends EventEmitter {
4141

4242
resolve(value) {
4343
this.value = value;
44+
this.status = DEFERRED_RESOLVED;
4445
this.emit('done', value);
4546
return this;
4647
}
4748

4849
reject(value) {
4950
this.value = value;
51+
this.status = DEFERRED_REJECTED;
5052
this.emit('fail', value);
5153
return this;
5254
}

0 commit comments

Comments
 (0)