Skip to content

Commit

Permalink
(new) Have side-effecting methods return the receiver instead of Void
Browse files Browse the repository at this point in the history
This allows these things to be chained.
  • Loading branch information
robotlolita committed Oct 16, 2016
1 parent cec13fd commit 7cf6f60
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/data/future/_future.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Future {
* ---
* category: Reacting to Future events
* type: |
* (Future 'f 's).(DeferredListener 'f 's) => Void
* (Future 'f 's).(DeferredListener 'f 's) => Future 'f 's
*/
listen(pattern) {
this._state.matchWith({
Expand All @@ -72,6 +72,7 @@ class Future {
Resolved: ({ value }) => pattern.onResolved(value),
Rejected: ({ reason }) => pattern.onRejected(reason)
});
return this;
}


Expand Down
11 changes: 8 additions & 3 deletions src/data/future/deferred.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ Deferred.prototype = {
* ---
* category: Resolving a deferred
* type: |
* ('a: Deferred 'f 's).('s) => Void :: mutates 'a
* ('a: Deferred 'f 's).('s) => 'a :: mutates 'a
*/
resolve(value) {
moveToState(this, Resolved(value));
return this;
},

/*~
Expand All @@ -105,10 +106,11 @@ Deferred.prototype = {
* ---
* category: Resolving a deferred
* type: |
* ('a: Deferred 'f 's).('f) => Void :: mutates 'a
* ('a: Deferred 'f 's).('f) => 'a :: mutates 'a
*/
reject(reason) {
moveToState(this, Rejected(reason));
return this;
},

/*~
Expand All @@ -117,16 +119,18 @@ Deferred.prototype = {
* ---
* category: Resolving a deferred
* type: |
* ('a: Deferred 'f 's).() => Void :: mutates 'a
* ('a: Deferred 'f 's).() => 'a :: mutates 'a
*/
cancel() {
moveToState(this, Cancelled());
return this;
},

maybeCancel() {
if (Pending.hasInstance(this._state)) {
this.cancel();
}
return this;
},


Expand All @@ -146,6 +150,7 @@ Deferred.prototype = {
Resolved: ({ value }) => pattern.onResolved(value),
Rejected: ({ reason }) => pattern.onRejected(reason)
});
return this;
},


Expand Down
2 changes: 2 additions & 0 deletions src/data/task/_task-execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ class TaskExecution {

cancel() {
this._deferred.maybeCancel();
return this;
}

listen(pattern) {
this._deferred.listen(pattern);
return this;
}

promise() {
Expand Down

0 comments on commit 7cf6f60

Please sign in to comment.