1
0
mirror of https://github.com/danog/amp.git synced 2025-01-22 13:21:16 +01:00

Add tests for iterator cancellation

This commit is contained in:
Niklas Keller 2021-12-02 23:10:12 +01:00
parent fb7e5b69a9
commit 9f6b75485f

View File

@ -29,6 +29,35 @@ class FutureTest extends AsyncTestCase
}
}
public function testIterateCancelPending(): void
{
$this->expectOutputString('');
$a = $this->delay(0.1, 'a');
$this->expectException(CancelledException::class);
foreach (Future::iterate([$a], new TimeoutCancellation(0.01)) as $index => $future) {
print $future->await() . '=' . $index . ' ';
}
}
public function testIterateCancelNonPending(): void
{
$this->expectOutputString('a=0 ');
$a = $this->delay(0.1, 'a');
$b = $this->delay(0.2, 'b');
$this->expectException(CancelledException::class);
$deferredCancellation = new DeferredCancellation;
foreach (Future::iterate([$a, $b], $deferredCancellation->getCancellation()) as $index => $future) {
$deferredCancellation->cancel();
print $future->await() . '=' . $index . ' ';
}
}
public function testIterateGenerator(): void
{
$this->expectOutputString('a=1 ');