Amp\Emitter::__construct PHP Method

__construct() public method

public __construct ( callable $emitter )
$emitter callable
    public function __construct(callable $emitter)
    {
        $result = $emitter($this->callableFromInstanceMethod("emit"));
        if (!$result instanceof \Generator) {
            throw new \Error("The callable did not return a Generator");
        }
        Loop::defer(function () use($result) {
            $coroutine = new Coroutine($result);
            $coroutine->when(function ($exception, $value) {
                if ($this->resolved) {
                    return;
                }
                if ($exception) {
                    $this->fail($exception);
                    return;
                }
                $this->resolve($value);
            });
        });
    }