You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These annotations will aid static analyses like PHPStan and Psalm to enhance type-safety for this project and projects depending on it
These changes make the following example understandable by PHPStan:
```php
final readonly class User
{
public function __construct(
public string $name,
)
}
/**
* \React\Promise\PromiseInterface<User>
*/
function getCurrentUserFromDatabase(): \React\Promise\PromiseInterface
{
// The following line would do the database query and fetch the result from it
// but keeping it simple for the sake of the example.
return \React\Promise\resolve(new User('WyriHaximus'));
}
// For the sake of this example we're going to assume the following code runs
// in \React\Async\async call
echo await(getCurrentUserFromDatabase())->name; // This echos: WyriHaximus
```
Copy file name to clipboardExpand all lines: README.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -226,7 +226,7 @@ await($promise);
226
226
227
227
### await()
228
228
229
-
The `await(PromiseInterface $promise): mixed` function can be used to
229
+
The `await(PromiseInterface<T> $promise): T` function can be used to
230
230
block waiting for the given `$promise` to be fulfilled.
231
231
232
232
```php
@@ -278,7 +278,7 @@ try {
278
278
279
279
### coroutine()
280
280
281
-
The `coroutine(callable $function, mixed ...$args): PromiseInterface<mixed>` function can be used to
281
+
The `coroutine((callable(mixed ...$args):(\Generator<mixed,PromiseInterface<T>,mixed,mixed>|T)) $function, mixed ...$args): PromiseInterface<T>` function can be used to
282
282
execute a Generator-based coroutine to "await" promises.
283
283
284
284
```php
@@ -498,7 +498,7 @@ Loop::addTimer(2.0, function () use ($promise): void {
498
498
499
499
### parallel()
500
500
501
-
The `parallel(iterable<callable():PromiseInterface<mixed>> $tasks): PromiseInterface<array<mixed>>` function can be used
501
+
The `parallel(iterable<callable():PromiseInterface<T>> $tasks): PromiseInterface<array<T>>` function can be used
502
502
like this:
503
503
504
504
```php
@@ -540,7 +540,7 @@ React\Async\parallel([
540
540
541
541
### series()
542
542
543
-
The `series(iterable<callable():PromiseInterface<mixed>> $tasks): PromiseInterface<array<mixed>>` function can be used
543
+
The `series(iterable<callable():PromiseInterface<T>> $tasks): PromiseInterface<array<T>>` function can be used
544
544
like this:
545
545
546
546
```php
@@ -582,7 +582,7 @@ React\Async\series([
582
582
583
583
### waterfall()
584
584
585
-
The `waterfall(iterable<callable(mixed=):PromiseInterface<mixed>> $tasks): PromiseInterface<mixed>` function can be used
585
+
The `waterfall(iterable<callable(mixed=):PromiseInterface<T>> $tasks): PromiseInterface<T>` function can be used
0 commit comments