* @template-implements \IteratorAggregate */ final class AutoDisposingPipeline implements Pipeline, \IteratorAggregate { /** @var EmitSource */ private EmitSource $source; public function __construct(EmitSource $source) { $this->source = $source; } public function __destruct() { $this->source->destroy(); } /** * @inheritDoc */ public function continue(): mixed { return $this->source->continue(); } /** * @inheritDoc */ public function dispose(): void { $this->source->dispose(); } /** * @inheritDoc * * @psalm-return \Traversable */ public function getIterator(): \Traversable { while (null !== $value = $this->source->continue()) { yield $value; } } }