Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
}
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.91",
"friendsofphp/php-cs-fixer": "^3.94",
"phpstan/phpstan": "^1.12",
"phpstan/phpstan-phpunit": "^1.4",
"phpstan/phpstan-strict-rules": "^1.6",
Expand Down
17 changes: 8 additions & 9 deletions lib/Promise.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,16 +186,15 @@ public function wait()
if (self::FULFILLED === $this->state) {
// If the state of this promise is fulfilled, we can return the value.
return $this->value;
} else {
// If we got here, it means that the asynchronous operation
// errored. Therefore, we need to throw an exception.
if ($this->value instanceof \Throwable) {
throw $this->value;
}
// The state should have been REJECTED, with "value" a Throwable
// But "value" was not a Throwable. So throw a more general exception.
throw new \LogicException('The Promise was not fulfilled but no exception was specified');
}
// If we got here, it means that the asynchronous operation
// errored. Therefore, we need to throw an exception.
if ($this->value instanceof \Throwable) {
throw $this->value;
}
// The state should have been REJECTED, with "value" a Throwable
// But "value" was not a Throwable. So throw a more general exception.
throw new \LogicException('The Promise was not fulfilled but no exception was specified');
}

/**
Expand Down
9 changes: 4 additions & 5 deletions lib/Promise/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,11 @@ function resolve($value): Promise
{
if ($value instanceof Promise) {
return $value->then();
} else {
$promise = new Promise();
$promise->fulfill($value);

return $promise;
}
$promise = new Promise();
$promise->fulfill($value);

return $promise;
}

/**
Expand Down
5 changes: 2 additions & 3 deletions lib/coroutine.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,9 @@ function (\Throwable $reason) use ($generator, $advanceGenerator) {
// We need to break out of the loop, because $advanceGenerator
// will be called asynchronously when the promise has a result.
break;
} else {
// If the value was not a promise, we'll just let it pass through.
$generator->send($yieldedValue);
}
// If the value was not a promise, we'll just let it pass through.
$generator->send($yieldedValue);
}

// If the generator is at the end, and we didn't run into an exception,
Expand Down