/** * Inform the coroutine that the executing strand is being terminated. * * @param StrandInterface $strand The strand that is executing the coroutine. */ public function terminate(StrandInterface $strand) { $strand->emit('terminate', [$strand]); $strand->emit('exit', [$strand]); $strand->removeAllListeners(); $strand->suspend(); }
/** * Invoked when tick() is called for the first time. * * @param StrandInterface $strand The strand that is executing the coroutine. */ public function call(StrandInterface $strand) { $strand->suspend(); $this->timer = $strand->kernel()->eventLoop()->addTimer($this->timeout, function () use($strand) { $strand->resumeWithValue(null); }); }
/** * Start the coroutine. * * @param StrandInterface $strand The strand that is executing the coroutine. */ public function call(StrandInterface $strand) { $strand->suspend(); $this->promise->then(function ($value) use($strand) { if ($this->promise) { $strand->resumeWithValue($value); } }, function ($reason) use($strand) { if ($this->promise) { $strand->resumeWithException($this->adaptReasonToException($reason)); } }); }
/** * Suspend the strand until the next tick. * * @param StrandInterface $strand The currently executing strand. */ public function cooperate(StrandInterface $strand) { $strand->suspend(); $strand->kernel()->eventLoop()->futureTick(function () use($strand) { $strand->resumeWithValue(null); }); }