1
0
mirror of https://github.com/danog/amp.git synced 2024-12-12 17:37:34 +01:00
amp/lib/Internal/AutoDisposingStream.php

48 lines
902 B
PHP
Raw Normal View History

2020-05-13 17:15:21 +02:00
<?php
namespace Amp\Internal;
use Amp\Promise;
use Amp\Stream;
/**
2020-05-28 19:59:55 +02:00
* Wraps a Stream instance that has public methods to emit, complete, and fail into an object that only allows
2020-05-13 17:15:21 +02:00
* 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
2020-05-13 17:15:21 +02:00
{
2020-05-28 19:59:55 +02:00
/** @var EmitSource<TValue, null> */
private $source;
2020-05-13 17:15:21 +02:00
2020-05-28 19:59:55 +02:00
public function __construct(EmitSource $source)
2020-05-13 17:15:21 +02:00
{
$this->source = $source;
2020-05-13 17:15:21 +02:00
}
public function __destruct()
{
$this->source->dispose();
2020-05-13 17:15:21 +02:00
}
/**
* @inheritDoc
2020-05-13 17:15:21 +02:00
*/
public function continue(): Promise
{
return $this->source->continue();
2020-05-13 17:15:21 +02:00
}
/**
* @inheritDoc
*/
public function dispose()
{
$this->source->dispose();
}
2020-05-13 17:15:21 +02:00
}