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

45 lines
995 B
PHP
Raw Normal View History

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