/** * Start the coroutine. * * @param StrandInterface $strand The strand that is executing the coroutine. */ public function call(StrandInterface $strand) { // If some of the strands have exited already, resume immediately ... if ($this->exited) { $strand->resumeWithValue($this->exited); return; } // Otherwise, suspend the current strand until at least one strand exits ... $this->strand = $strand; $this->strand->suspend(); foreach ($this->substrands as $strand) { $strand->on('exit', [$this, 'onStrandExit']); } }