Ejemplo n.º 1
0
 protected function connectSocket(Uri $uri) : Awaitable
 {
     return new Coroutine(function () {
         list($a, $b) = Socket::createPair();
         $this->socket = new SocketStream($b);
         return new SocketStream($a);
     });
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 protected function spawnWorker() : Awaitable
 {
     if (self::$sharedWorkers === null) {
         self::$sharedWorkers = [];
         \register_shutdown_function(function () {
             self::shutdownPool();
         });
     }
     $index = self::$allocated++ % self::getMaxSize();
     if (isset(self::$sharedWorkers[$index])) {
         return new Success(self::$sharedWorkers[$index]);
     }
     try {
         list($a, $b) = Socket::createPair();
         $thread = new Thread($b, self::getComposerAutoloader());
         $thread->start(\PTHREADS_INHERIT_INI);
         return new Success(self::$sharedWorkers[$index] = new ThreadWorker($index, $a, $thread));
     } catch (\Throwable $e) {
         self::$allocated--;
         return new Failure($e);
     }
 }
Ejemplo n.º 3
0
 public function __construct(callable $client, callable $server)
 {
     list($clientSocket, $serverSocket) = Socket::createPair();
     $this->resolve($this->await = new AwaitAll([new Coroutine($this->runClient($clientSocket, $client)), new Coroutine($this->runServer($serverSocket, $server))]));
 }