init(); /** * @param mixed $value * * @return \Interop\Async\Awaitable */ $emit = function ($value) { return $this->emit($value); }; $result = $emitter($emit); if (!$result instanceof \Generator) { throw new \LogicException("The callable did not return a Generator"); } $coroutine = new Coroutine($result); $coroutine->when(function ($exception, $value) { if ($exception) { $this->fail($exception); return; } $this->resolve($value); }); } }