1
0
mirror of https://github.com/danog/amp.git synced 2024-12-04 18:38:17 +01:00
amp/lib/Internal/PrivateIterator.php
Aaron Piotrowski 0eceb48fad
Refactor internal traits as classes
Trait tests should test Deferred and Emitter instead, will update with other tests.
2020-09-26 23:14:17 -05:00

46 lines
898 B
PHP

<?php
namespace Amp\Internal;
use Amp\Iterator;
use Amp\Promise;
/**
* Wraps a Producer instance that has public methods to emit, complete, and fail into an object that only allows
* access to the public API methods.
*
* @template-covariant TValue
* @template-implements Iterator<TValue>
*/
final class PrivateIterator implements Iterator
{
/** @var Producer<TValue> */
private Producer $producer;
/**
* @param Producer $producer
*
* @psalm-param Iterator<TValue> $iterator
*/
public function __construct(Producer $producer)
{
$this->producer = $producer;
}
/**
* @return Promise<bool>
*/
public function advance(): Promise
{
return $this->producer->advance();
}
/**
* @psalm-return TValue
*/
public function getCurrent()
{
return $this->producer->getCurrent();
}
}