process(); } $instance = $proceedingJoinPoint->getInstance(); if (isset(self::$coSockets[$instance]) && self::$coSockets[$instance] instanceof Socket) { return self::$coSockets[$instance]; } return self::$coSockets[$instance] = (function () use ($proceedingJoinPoint) { $nonCoSocket = $this->socket; // Save the socket of non-coroutine. $this->socket = null; // Unset the socket of non-coroutine. $coSocket = $proceedingJoinPoint->process(); // ReCreate the socket in coroutine. $this->socket = $nonCoSocket; // Restore the socket of non-coroutine. return $coSocket; })->call($instance); } }