1
0
mirror of https://github.com/danog/amp.git synced 2025-01-22 21:31:18 +01:00
amp/lib/Internal/AutoDisposingPipeline.php
2020-09-24 12:53:31 -05:00

48 lines
912 B
PHP

<?php
namespace Amp\Internal;
use Amp\Pipeline;
use Amp\Promise;
/**
* Wraps a Pipeline instance that has public methods to emit, complete, and fail into an object that only allows
* access to the public API methods and sets $disposed to true when the object is destroyed.
*
* @internal
*
* @template-covariant TValue
* @template-implements Pipeline<TValue>
*/
final class AutoDisposingPipeline implements Pipeline
{
/** @var EmitSource<TValue, null> */
private $source;
public function __construct(EmitSource $source)
{
$this->source = $source;
}
public function __destruct()
{
$this->source->dispose();
}
/**
* @inheritDoc
*/
public function continue(): Promise
{
return $this->source->continue();
}
/**
* @inheritDoc
*/
public function dispose()
{
$this->source->dispose();
}
}