From ac75117a0790c1b7ad6171d1d2eeb8f8ee2c172e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Sun, 23 Jul 2023 17:30:58 +0200 Subject: [PATCH] Use Promise v3 template types --- README.md | 6 +++--- src/Queue.php | 33 +++++++++++++++++++++------------ 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index c32c57c..b68bc72 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ is reached, it will not start a new operation and instead queue this for future execution. Once one of the pending operations complete, it will pick the next job from the queue and execute this operation. -The `new Queue(int $concurrency, ?int $limit, callable $handler)` call +The `new Queue(int $concurrency, ?int $limit, callable(mixed):PromiseInterface $handler)` call can be used to create a new queue instance. You can create any number of queues, for example when you want to apply different limits to different kinds of operations. @@ -275,7 +275,7 @@ for more details. #### all() -The static `all(int $concurrency, array $jobs, callable $handler): PromiseInterface` method can be used to +The static `all(int $concurrency, array $jobs, callable(TIn):PromiseInterface $handler): PromiseInterface>` method can be used to concurrently process all given jobs through the given `$handler`. This is a convenience method which uses the `Queue` internally to @@ -349,7 +349,7 @@ $promise = Queue::all(10, $jobs, array($browser, 'get')); #### any() -The static `any(int $concurrency, array $jobs, callable $handler): PromiseInterface` method can be used to +The static `any(int $concurrency, array $jobs, callable(TIn):Promise $handler): PromiseInterface` method can be used to concurrently process the given jobs through the given `$handler` and resolve with first resolution value. diff --git a/src/Queue.php b/src/Queue.php index 29357d6..60020a5 100644 --- a/src/Queue.php +++ b/src/Queue.php @@ -18,6 +18,8 @@ * is reached, it will not start a new operation and instead queue this for future * execution. Once one of the pending operations complete, it will pick the next * job from the queue and execute this operation. + * + * @template T */ class Queue implements \Countable { @@ -100,10 +102,13 @@ class Queue implements \Countable * > Keep in mind that returning an array of response messages means that * the whole response body has to be kept in memory. * - * @param int $concurrency concurrency soft limit - * @param array $jobs - * @param callable $handler - * @return PromiseInterface Returns a Promise which resolves with an array of all resolution values + * @template TKey + * @template TIn + * @template TOut + * @param int $concurrency concurrency soft limit + * @param array $jobs + * @param callable(TIn):PromiseInterface $handler + * @return PromiseInterface> Returns a Promise which resolves with an array of all resolution values * or rejects when any of the operations reject. */ public static function all($concurrency, array $jobs, $handler) @@ -212,10 +217,13 @@ public static function all($concurrency, array $jobs, $handler) * $promise = Queue::any(10, $jobs, array($browser, 'get')); * ``` * - * @param int $concurrency concurrency soft limit - * @param array $jobs - * @param callable $handler - * @return PromiseInterface Returns a Promise which resolves with a single resolution value + * @template TKey + * @template TIn + * @template TOut + * @param int $concurrency concurrency soft limit + * @param array $jobs + * @param callable(TIn):PromiseInterface $handler + * @return PromiseInterface Returns a Promise which resolves with a single resolution value * or rejects when all of the operations reject. */ public static function any($concurrency, array $jobs, $handler) @@ -307,9 +315,9 @@ public static function any($concurrency, array $jobs, $handler) * $q = new Queue(10, null, array($browser, 'get')); * ``` * - * @param int $concurrency concurrency soft limit - * @param int|null $limit queue hard limit or NULL=unlimited - * @param callable $handler + * @param int $concurrency concurrency soft limit + * @param int|null $limit queue hard limit or NULL=unlimited + * @param callable(mixed):PromiseInterface $handler * @throws \InvalidArgumentException */ public function __construct($concurrency, $limit, $handler) @@ -338,7 +346,7 @@ public function __construct($concurrency, $limit, $handler) * completed. This means that this is handled entirely transparently and you do not * need to worry about this concurrency limit yourself. * - * @return \React\Promise\PromiseInterface + * @return PromiseInterface */ public function __invoke() { @@ -395,6 +403,7 @@ public function count() /** * @internal + * @param PromiseInterface $promise */ public function await(PromiseInterface $promise) {