public function next() : Promise
{
if (isset($this->deferreds[$this->position])) {
$future = $this->deferreds[$this->position];
unset($this->values[$this->position], $this->deferreds[$this->position]);
$future->resolve();
}
++$this->position;
if (\array_key_exists($this->position, $this->values)) {
return new Success(true);
}
if ($this->resolved) {
--$this->position;
if ($this->exception) {
return new Failure($this->exception);
}
return new Success(false);
}
$this->deferred = new Deferred();
return $this->deferred->promise();
}