Skip to content

Recommend rejecting promises by throwing an exception #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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