Exemple #1
0
 /**
  * Run
  */
 public function run()
 {
     if ($this->running) {
         throw new \RuntimeException("Cluster already running");
     }
     $this->running = true;
     $that = $this;
     // Process middlewares
     foreach ($this->options['stacks'] as $stack) {
         $fn = Middleware::build($stack[0], $stack[1]);
         if (!$fn) {
             throw new \RuntimeException("Error middleware: " . $stack[0]);
         }
         $fn($this);
     }
     // Register tick
     $this->manager->on('tick', function () use($that) {
         $that->tickCheck();
     });
     // Run workers
     foreach ($this->workers as $worker) {
         $worker->run();
     }
 }