Skip to content

Commit 74c1d0c

Browse files
authored
Merge pull request #42 from clue-labs/template-types
Use Promise v3 template types
2 parents 55f6c80 + ac75117 commit 74c1d0c

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ is reached, it will not start a new operation and instead queue this for future
107107
execution. Once one of the pending operations complete, it will pick the next
108108
job from the queue and execute this operation.
109109

110-
The `new Queue(int $concurrency, ?int $limit, callable $handler)` call
110+
The `new Queue(int $concurrency, ?int $limit, callable(mixed):PromiseInterface<T> $handler)` call
111111
can be used to create a new queue instance.
112112
You can create any number of queues, for example when you want to apply
113113
different limits to different kinds of operations.
@@ -275,7 +275,7 @@ for more details.
275275

276276
#### all()
277277

278-
The static `all(int $concurrency, array $jobs, callable $handler): PromiseInterface<mixed[]>` method can be used to
278+
The static `all(int $concurrency, array<TKey,TIn> $jobs, callable(TIn):PromiseInterface<TOut> $handler): PromiseInterface<array<TKey,TOut>>` method can be used to
279279
concurrently process all given jobs through the given `$handler`.
280280

281281
This is a convenience method which uses the `Queue` internally to
@@ -349,7 +349,7 @@ $promise = Queue::all(10, $jobs, array($browser, 'get'));
349349

350350
#### any()
351351

352-
The static `any(int $concurrency, array $jobs, callable $handler): PromiseInterface<mixed>` method can be used to
352+
The static `any(int $concurrency, array<TKey,TIn> $jobs, callable(TIn):Promise<TOut> $handler): PromiseInterface<TOut>` method can be used to
353353
concurrently process the given jobs through the given `$handler` and
354354
resolve with first resolution value.
355355

src/Queue.php

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
* is reached, it will not start a new operation and instead queue this for future
1919
* execution. Once one of the pending operations complete, it will pick the next
2020
* job from the queue and execute this operation.
21+
*
22+
* @template T
2123
*/
2224
class Queue implements \Countable
2325
{
@@ -100,10 +102,13 @@ class Queue implements \Countable
100102
* > Keep in mind that returning an array of response messages means that
101103
* the whole response body has to be kept in memory.
102104
*
103-
* @param int $concurrency concurrency soft limit
104-
* @param array $jobs
105-
* @param callable $handler
106-
* @return PromiseInterface Returns a Promise<mixed[]> which resolves with an array of all resolution values
105+
* @template TKey
106+
* @template TIn
107+
* @template TOut
108+
* @param int $concurrency concurrency soft limit
109+
* @param array<TKey,TIn> $jobs
110+
* @param callable(TIn):PromiseInterface<TOut> $handler
111+
* @return PromiseInterface<array<TKey,TOut>> Returns a Promise which resolves with an array of all resolution values
107112
* or rejects when any of the operations reject.
108113
*/
109114
public static function all($concurrency, array $jobs, $handler)
@@ -212,10 +217,13 @@ public static function all($concurrency, array $jobs, $handler)
212217
* $promise = Queue::any(10, $jobs, array($browser, 'get'));
213218
* ```
214219
*
215-
* @param int $concurrency concurrency soft limit
216-
* @param array $jobs
217-
* @param callable $handler
218-
* @return PromiseInterface Returns a Promise<mixed> which resolves with a single resolution value
220+
* @template TKey
221+
* @template TIn
222+
* @template TOut
223+
* @param int $concurrency concurrency soft limit
224+
* @param array<TKey,TIn> $jobs
225+
* @param callable(TIn):PromiseInterface<TOut> $handler
226+
* @return PromiseInterface<TOut> Returns a Promise which resolves with a single resolution value
219227
* or rejects when all of the operations reject.
220228
*/
221229
public static function any($concurrency, array $jobs, $handler)
@@ -307,9 +315,9 @@ public static function any($concurrency, array $jobs, $handler)
307315
* $q = new Queue(10, null, array($browser, 'get'));
308316
* ```
309317
*
310-
* @param int $concurrency concurrency soft limit
311-
* @param int|null $limit queue hard limit or NULL=unlimited
312-
* @param callable $handler
318+
* @param int $concurrency concurrency soft limit
319+
* @param int|null $limit queue hard limit or NULL=unlimited
320+
* @param callable(mixed):PromiseInterface<T> $handler
313321
* @throws \InvalidArgumentException
314322
*/
315323
public function __construct($concurrency, $limit, $handler)
@@ -338,7 +346,7 @@ public function __construct($concurrency, $limit, $handler)
338346
* completed. This means that this is handled entirely transparently and you do not
339347
* need to worry about this concurrency limit yourself.
340348
*
341-
* @return \React\Promise\PromiseInterface
349+
* @return PromiseInterface<T>
342350
*/
343351
public function __invoke()
344352
{
@@ -395,6 +403,7 @@ public function count()
395403

396404
/**
397405
* @internal
406+
* @param PromiseInterface<T> $promise
398407
*/
399408
public function await(PromiseInterface $promise)
400409
{

0 commit comments

Comments
 (0)