2020-05-13 17:15:21 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Amp\Internal;
|
|
|
|
|
|
|
|
use Amp\Promise;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Wraps a GeneratorStream 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 TValue
|
|
|
|
* @template TSend
|
|
|
|
*
|
|
|
|
* @template-implements GeneratorStream<TValue, TSend>
|
|
|
|
*/
|
2020-05-13 21:59:31 +02:00
|
|
|
class AutoDisposingGenerator extends AutoDisposingStream implements GeneratorStream
|
2020-05-13 17:15:21 +02:00
|
|
|
{
|
|
|
|
/** @var GeneratorStream<TValue, TSend> */
|
|
|
|
private $generator;
|
|
|
|
|
2020-05-13 21:59:31 +02:00
|
|
|
public function __construct(GeneratorStream $generator)
|
2020-05-13 17:15:21 +02:00
|
|
|
{
|
2020-05-13 21:59:31 +02:00
|
|
|
parent::__construct($generator);
|
2020-05-13 17:15:21 +02:00
|
|
|
$this->generator = $generator;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-05-14 21:14:54 +02:00
|
|
|
* @inheritDoc
|
2020-05-13 17:15:21 +02:00
|
|
|
*/
|
|
|
|
public function send($value): Promise
|
|
|
|
{
|
|
|
|
return $this->generator->send($value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-05-14 21:14:54 +02:00
|
|
|
* @inheritDoc
|
2020-05-13 17:15:21 +02:00
|
|
|
*/
|
|
|
|
public function throw(\Throwable $exception): Promise
|
|
|
|
{
|
|
|
|
return $this->generator->throw($exception);
|
|
|
|
}
|
|
|
|
}
|