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:28 -05:00

57 lines
1.1 KiB
PHP

<?php
namespace Amp\Internal;
use Amp\TransformationStream;
use Amp\Promise;
use Amp\Stream;
/**
* Wraps a Stream instance that has public methods to yield, 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>
*/
class AutoDisposingStream implements Stream
{
/** @var Stream<TValue> */
private $stream;
public function __construct(Stream $stream)
{
$this->stream = $stream;
}
public function __destruct()
{
$this->stream->dispose();
}
/**
* @return Promise<array>
*/
public function continue(): Promise
{
return $this->stream->continue();
}
/**
* @return void
*/
public function dispose()
{
$this->stream->dispose();
}
/**
* @return TransformationStream
*/
public function transform(): TransformationStream
{
return $this->stream->transform();
}
}