Exemple #1
0
 /**
  * @codeCoverageIgnore
  */
 private static function shutdownPool()
 {
     Loop::execute(function () {
         $awaitables = [];
         try {
             foreach (self::$sharedWorkers as $worker) {
                 try {
                     $awaitables[] = $worker->dispose();
                 } catch (\Throwable $e) {
                     fwrite(STDERR, "THREAD POOL SHUTDOWN ERROR:\n{$e}");
                 }
             }
         } finally {
             self::$sharedWorkers = null;
         }
         $await = new AwaitAll($awaitables);
         $await->when(function ($e = null, array $threads = null) {
             foreach ((array) $threads as $thread) {
                 $thread->join();
             }
         });
     }, new NativeLoop());
 }
Exemple #2
0
 /**
  * @codeCoverageIgnore
  */
 private static function shutdownPool()
 {
     Loop::execute(function () {
         $await = [];
         try {
             foreach (self::$handshakes as list($worker, $defer)) {
                 $defer->fail(new PoolShutdownException('Pool shut down during worker handshake'));
                 $await[] = $worker->dispose();
             }
         } catch (\Throwable $e) {
             fwrite(STDERR, "PROCESS POOL SHUTDOWN ERROR:\n{$e}");
         } finally {
             self::$handshakes = [];
         }
         try {
             foreach (self::$sharedWorkers as $worker) {
                 $await[] = $worker->dispose();
             }
         } catch (\Throwable $e) {
             fwrite(STDERR, "PROCESS POOL SHUTDOWN ERROR:\n{$e}");
         } finally {
             self::$sharedWorkers = null;
         }
         if (self::$serverAwait !== null) {
             try {
                 self::$serverAwait->cancel(new PoolShutdownException('Handshakes done'));
             } catch (\Throwable $e) {
                 fwrite(STDERR, "PROCESS POOL SHUTDOWN ERROR:\n{$e}");
             }
         }
         if (!empty($await)) {
             $await = new AwaitAll($await);
             $await->when(function ($e = null, array $val = null) {
                 if (self::$server !== null) {
                     try {
                         @\fclose(self::$server);
                     } finally {
                         self::$server = null;
                     }
                 }
             });
         }
     }, new NativeLoop());
 }