lib/Internal/Producer.php
private function emit($value): Promise
    {
        if ($this->complete) {
            throw new \Error("Iterators cannot emit values after calling complete");
        }

        if ($value instanceof ReactPromise) {
            $value = Promise\adapt($value);
        }

        if ($value instanceof Promise) {
            $deferred = new Deferred;
            $value->onResolve(function ($e, $v) use ($deferred) {
                if ($this->complete) {
                    $deferred->fail(
                        new \Error("The iterator was completed before the promise result could be emitted")
                    );
                    return;
                }

                if ($e) {
                    $this->fail($e);
                    $deferred->fail($e);
                    return;
                }

                $deferred->resolve($this->emit($v));
            });

            return $deferred->promise();
        }

        $this->values[] = $value;
        $this->backPressure[] = $pressure = new Deferred;

        if ($this->waiting !== null) {
            $waiting = $this->waiting;
            $this->waiting = null;
            $waiting->resolve(true);
        }

        return $pressure->promise();
    }
private function emit($value): Promise
    {
        if ($this->complete) {
            throw new \Error("Iterators cannot emit values after calling complete");
        }

        if ($value instanceof ReactPromise) {
            $value = Promise\adapt($value);
        }

        if ($value instanceof Promise) {
            $deferred = new Deferred;
            $value->onResolve(function ($e, $v) use ($deferred) {
                if ($this->complete) {
                    $deferred->fail(
                        new \Error("The iterator was completed before the promise result could be emitted")
                    );
                    return;
                }

                if ($e) {
                    $this->fail($e);
                    $deferred->fail($e);
                    return;
                }

                $deferred->resolve($this->emit($v));
            });

            return $deferred->promise();
        }

        $this->values[] = $value;
        $this->backPressure[] = $pressure = new Deferred;

        if ($this->waiting !== null) {
            $waiting = $this->waiting;
            $this->waiting = null;
            $waiting->resolve(true);
        }

        return $pressure->promise();
    }
private function emit ( $ value ) : Promise { if ( $ this -> complete ) { throw new \ Error ( "Iterators cannot emit values after calling complete" ) ; } if ( $ value instanceof ReactPromise ) { $ value = Promise \ adapt ( $ value ) ; } if ( $ value instanceof Promise ) { $ deferred = new Deferred ; $ value -> onResolve ( function ( $ e , $ v ) use ( $ deferred ) { if ( $ this -> complete ) { $ deferred -> fail ( new \ Error ( "The iterator was completed before the promise result could be emitted" ) ) ; return ; } if ( $ e ) { $ this -> fail ( $ e ) ; $ deferred -> fail ( $ e ) ; return ; } $ deferred -> resolve ( $ this -> emit ( $ v ) ) ; } ) ; return $ deferred -> promise ( ) ; } $ this -> values [ ] = $ value ; $ this -> backPressure [ ] = $ pressure = new Deferred ; if ( $ this -> waiting !== null ) { $ waiting = $ this -> waiting ; $ this -> waiting = null ; $ waiting -> resolve ( true ) ; } return $ pressure -> promise ( ) ; }
Emits a value from the iterator. The returned promise is resolved with the emitted value once all listeners
have been invoked.

@param mixed $value

@return \Amp\Promise

@throws \Error If the iterator has completed.
Emits a value from the iterator . The returned promise is resolved with the emitted value once all listeners have been invoked .