1
0
mirror of https://github.com/danog/amp.git synced 2024-12-11 17:09:40 +01:00
amp/lib/Internal/AutoDisposingPipeline.php
2020-09-24 22:14:58 -05:00

47 lines
932 B
PHP

<?php
namespace Amp\Internal;
use Amp\Pipeline;
/**
* Wraps an EmitSource instance that has public methods to emit, complete, and fail into an object that only allows
* access to the public API methods and automatically calls EmitSource::destroy() when the object is destroyed.
*
* @internal
*
* @template-covariant TValue
* @template-implements Pipeline<TValue>
*/
final class AutoDisposingPipeline implements Pipeline
{
/** @var EmitSource<TValue, null> */
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();
}
}