Skip to content

Commit 158476b

Browse files
committed
Add comprehensive CancellablePromise test suite and update timeout return types
- Add 789-line test suite covering CancellablePromise functionality including state management, cancellation handlers, promise chaining, and real-world usage examples - Update timeout method return types from PromiseInterface to CancellablePromiseInterface across AsyncOperations, PromiseCollectionHandler, and helper functions - Add CancellablePromiseInterface import to PromiseCollectionHandler
1 parent 24cd096 commit 158476b

File tree

4 files changed

+796
-6
lines changed

4 files changed

+796
-6
lines changed

src/Async/AsyncOperations.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,9 @@ public function any(array $promises): PromiseInterface
201201

202202
/**
203203
* @param callable(): PromiseInterface<mixed>|PromiseInterface<mixed>|array<int|string, callable(): PromiseInterface<mixed>|PromiseInterface<mixed>> $promises
204-
* @return PromiseInterface<mixed>
204+
* @return CancellablePromiseInterface<mixed>
205205
*/
206-
public function timeout(callable|PromiseInterface|array $promises, float $seconds): PromiseInterface
206+
public function timeout(callable|PromiseInterface|array $promises, float $seconds): CancellablePromiseInterface
207207
{
208208
return $this->collectionHandler->timeout($promises, $seconds);
209209
}

src/Async/Handlers/PromiseCollectionHandler.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Exception;
66
use InvalidArgumentException;
77
use Rcalicdan\FiberAsync\Promise\CancellablePromise;
8+
use Rcalicdan\FiberAsync\Promise\Interfaces\CancellablePromiseInterface;
89
use Rcalicdan\FiberAsync\Promise\Interfaces\PromiseInterface;
910
use Rcalicdan\FiberAsync\Promise\Promise;
1011
use RuntimeException;
@@ -162,7 +163,7 @@ public function race(array $promises): PromiseInterface
162163
public function timeout(
163164
callable|PromiseInterface|array $operations,
164165
float $seconds
165-
): PromiseInterface {
166+
): CancellablePromiseInterface {
166167
if ($seconds <= 0) {
167168
throw new InvalidArgumentException('Timeout must be greater than zero');
168169
}
@@ -180,7 +181,7 @@ public function timeout(
180181
->then(fn () => throw new Exception("Operation timed out after {$seconds} seconds"))
181182
;
182183

183-
/** @var array<int|string, callable(): PromiseInterface<mixed>|PromiseInterface<mixed>> $racePromises */
184+
/** @var array<int|string, callable(): CancellablePromiseInterface<mixed>|CancellablePromiseInterface<mixed>> $racePromises */
184185
$racePromises = [...$promises, $timeoutPromise];
185186

186187
return $this->race($racePromises);

src/Helpers/async_helper.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ function any(array $promises): PromiseInterface
164164
*
165165
* @param callable|PromiseInterface<mixed>|array<PromiseInterface<mixed>> $promises Number of seconds to wait before resolving
166166
* @param float $seconds Number of seconds to wait before resolving
167-
* @return PromiseInterface<mixed> A promise that resolves after the delay
167+
* @return CancellablePromiseInterface<mixed> A promise that resolves after the delay
168168
*/
169-
function timeout(callable|PromiseInterface|array $promises, float $seconds): PromiseInterface
169+
function timeout(callable|PromiseInterface|array $promises, float $seconds): CancellablePromiseInterface
170170
{
171171
return Promise::timeout($promises, $seconds);
172172
}

0 commit comments

Comments
 (0)