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); }); }); } }