mirror of
https://github.com/danog/amp.git
synced 2024-12-11 17:09:40 +01:00
47 lines
932 B
PHP
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();
|
|
}
|
|
}
|