Skip to content

Commit 614ae88

Browse files
authored
Merge pull request #26 from async-interop/when-invocation
Require sync "when" invocations after resolution
2 parents 587a63e + 88cf01c commit 614ae88

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Any implementation MUST at least provide these two parameters. The implementatio
7272

7373
> **NOTE:** The signature doesn't specify a type for `$error`. This is due to the new `Throwable` interface introduced in PHP 7. As this specification is PHP 5 compatible, we can use neither `Throwable` nor `Exception`.
7474
75-
All registered callbacks MUST be executed in the order they were registered. If one of the callbacks throws an `Exception` or `Throwable`, it MUST be forwarded to `Async\Interop\Promise\ErrorHandler::notify`. The `Promise` implementation MUST then continue to call the remaining callbacks with the original parameters.
75+
All callbacks registered before the resolution MUST be executed in the order they were registered. Callbacks registered after the resolution MUST be executed immediately. If one of the callbacks throws an `Exception` or `Throwable`, it MUST be forwarded to `Async\Interop\Promise\ErrorHandler::notify`. The `Promise` implementation MUST then continue to call the remaining callbacks with the original parameters.
7676

7777
Registered callbacks MUST NOT be called from a file with strict types enabled (`declare(strict_types=1)`).
7878

src/Promise.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,14 @@ interface Promise
1010
/**
1111
* Registers a callback to be invoked when the promise is resolved.
1212
*
13-
* @param callable(\Throwable|\Exception|null $exception, mixed $result) $onResolved
13+
* The callback receives `null` as first parameter and `$value` as second parameter on success. It receives the
14+
* failure reason as first parameter and `null` as second parameter on failure.
15+
*
16+
* If the promise is already resolved, the callback MUST be executed immediately.
17+
*
18+
* Warning: If you use type declarations for `$value`, be sure to make them accept `null` in case of failures.
19+
*
20+
* @param callable(\Throwable|\Exception|null $exception, mixed $value) $onResolved Callback to be executed.
1421
*
1522
* @return void
1623
*/

0 commit comments

Comments
 (0)