public function testDealerRep() { $pids[] = $this->forkRepWorker(); $pids[] = $this->forkRepWorker(); $loop = new StreamSelectLoop(); $context = new Context($loop); $dealer = $context->getSocket(\ZMQ::SOCKET_DEALER); $dealer->bind('ipc://test2.ipc'); sleep(1); $msgs = array(); $dealer->on('message', function ($msg) use(&$msgs) { $msgs[] = $msg; }); $dealer->send(array('A', '', 'foo')); $dealer->send(array('B', '', 'bar')); $loop->addTimer(1, function () use($loop) { $loop->stop(); }); $loop->run(); foreach ($pids as $pid) { pcntl_waitpid($pid, $status, WUNTRACED); } $this->assertCount(2, $msgs); $this->assertContains(array('A', '', 'foobar'), $msgs); $this->assertContains(array('B', '', 'barbar'), $msgs); }
/** * Retry connecting to the transport */ public function retryConnection() { $options = $this->reconnectOptions; if ($this->attemptRetry === false) { return; } if ($options['max_retries'] <= $this->retryAttempts) { return; } $this->retryAttempts++; if ($this->retryTimer >= $options['max_retry_delay']) { $this->retryTimer = $options['max_retry_delay']; } elseif ($this->retryTimer == 0) { $this->retryTimer = $options['initial_retry_delay']; } else { $this->retryTimer = $this->retryTimer * $options['retry_delay_growth']; } $this->loop->addTimer($this->retryTimer, function () { $this->transportProvider->startTransportProvider($this, $this->loop); }); }
public function after($duration, $fn) { $this->loop->addTimer($this->timerOffset + $duration, $fn); $this->timerOffset += $duration; return $this; }