Skip to content

Commit

Permalink
Accept Throwable as rejection reason
Browse files Browse the repository at this point in the history
  • Loading branch information
ste93cry committed Nov 25, 2023
1 parent 7fa2284 commit e80412d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Change Log

## 1.2.2

### Fixed

- Fix accepting `Throwable` as rejection reason of a promise

## 1.2.1

### Added
Expand Down
4 changes: 2 additions & 2 deletions src/FulfilledPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public function then(callable $onFulfilled = null, callable $onRejected = null)

try {
return new self($onFulfilled($this->result));
} catch (\Exception $e) {
return new RejectedPromise($e);
} catch (\Throwable $exception) {
return new RejectedPromise($exception);
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/RejectedPromise.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
final class RejectedPromise implements Promise
{
/**
* @var \Exception
* @var \Throwable
*/
private $exception;

public function __construct(\Exception $exception)
public function __construct(\Throwable $exception)
{
$this->exception = $exception;
}
Expand All @@ -34,8 +34,8 @@ public function then(callable $onFulfilled = null, callable $onRejected = null)

try {
return new FulfilledPromise($onRejected($this->exception));
} catch (\Exception $e) {
return new self($e);
} catch (\Throwable $exception) {
return new self($exception);
}
}

Expand Down

0 comments on commit e80412d

Please sign in to comment.