Skip to content

Commit

Permalink
Merge pull request #114 from jsor-labs/recommend-throwing-over-reject
Browse files Browse the repository at this point in the history
Recommend rejecting promises by throwing an exception
  • Loading branch information
jsor committed Apr 25, 2018
2 parents 389551e + 4ea1d71 commit b0242fc
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -372,15 +372,17 @@ $resolver = function (callable $resolve, callable $reject, callable $notify) {
// along the way if you want/need.

$resolve($awesomeResult);
// or throw new Exception('Promise rejected');
// or $resolve($anotherPromise);
// or $reject($nastyError);
// or $notify($progressNotification);
};

$canceller = function (callable $resolve, callable $reject, callable $progress) {
$canceller = function () {
// Cancel/abort any running operations like network connections, streams etc.

$reject(new \Exception('Promise cancelled'));
// Reject promise by throwing an exception
throw new Exception('Promise cancelled');
};

$promise = new React\Promise\Promise($resolver, $canceller);
Expand All @@ -394,7 +396,8 @@ function which both will be called with 3 arguments:
When called with a non-promise value, fulfills promise with that value.
When called with another promise, e.g. `$resolve($otherPromise)`, promise's
fate will be equivalent to that of `$otherPromise`.
* `$reject($reason)` - Function that rejects the promise.
* `$reject($reason)` - Function that rejects the promise. It is recommended to
just throw an exception instead of using `$reject()`.
* `$notify($update)` - Deprecated function that issues progress events for the promise.

If the resolver or canceller throw an exception, the promise will be rejected
Expand Down

0 comments on commit b0242fc

Please sign in to comment.