Adds a visitor to be invoked when the deferred's state changes.
Adds a visitor to be invoked when the deferred's state changes.
listen(pattern) {
this._state.matchWith({
Pending: _ => this._listeners.push(pattern),
Cancelled: _ => pattern.onCancelled(),
Resolved: ({ value }) => pattern.onResolved(value),
Rejected: ({ reason }) => pattern.onRejected(reason)
});
return this;
}