1
0
mirror of https://github.com/danog/amp.git synced 2024-12-12 09:29:45 +01:00
amp/lib/Internal/AutoDisposingStream.php
2020-09-24 12:53:30 -05:00

48 lines
902 B
PHP

<?php
namespace Amp\Internal;
use Amp\Promise;
use Amp\Stream;
/**
* Wraps a Stream 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 Stream<TValue>
*/
final class AutoDisposingStream implements Stream
{
/** @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();
}
}