Skip to content

Commit

Permalink
Cancel on disposal
Browse files Browse the repository at this point in the history
  • Loading branch information
trowski committed Jan 30, 2022
1 parent d93ef07 commit c2a5be2
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/Internal/ConcurrentClosureIterator.php
Expand Up @@ -34,8 +34,14 @@ public function __construct(\Closure $supplier)
$this->supplier = $supplier;
$this->sequence = new Sequence();
$this->queue = new QueueState();
$this->sources = new \SplQueue();
$this->sources = $sources = new \SplQueue();
$this->deferredCancellation = new DeferredCancellation();

$this->deferredCancellation->getCancellation()->subscribe(static function () use ($sources): void {
while ($sources->isEmpty()) {
$sources->dequeue();
}
});
}

public function continue(?Cancellation $cancellation = null): bool
Expand Down Expand Up @@ -117,11 +123,8 @@ public function getPosition(): int

public function dispose(): void
{
while (!$this->sources->isEmpty()) {
$this->sources->dequeue();
}

$this->queue->dispose();
$this->deferredCancellation->cancel();
}

public function getIterator(): \Traversable
Expand Down

0 comments on commit c2a5be2

Please sign in to comment.