コード例 #1
0
 /**
  * Sets the event loop instance.
  *
  * @param \React\EventLoop\LoopInterface $loop
  *
  * @todo find some way to do a unit test for this method
  */
 public function setLoop(LoopInterface $loop)
 {
     parent::setLoop($loop);
     \React\Promise\Timer\timeout(MessengerFactory::parentFromClass('PSchwisow\\Phergie\\Plugin\\Karma\\ChildProcess', $loop), 10.0, $loop)->then(function (Messenger $messenger) use($loop) {
         $this->logDebug('got a messenger');
         $this->messenger = $messenger;
         $messenger->on('error', function ($e) {
             $this->logDebug('Error: ' . var_export($e, true));
         });
         $this->messenger->rpc(MessageFactory::rpc('config', $this->config))->then(function ($payload) {
             $this->logDebug('configuration sent to child. Response: ' . var_export($payload, true));
         });
     }, function ($error) {
         if ($error instanceof \React\Promise\Timer\TimeoutException) {
             // the operation has failed due to a timeout
             $this->logDebug('TIMEOUT');
         } else {
             // the input operation has failed due to some other error
             $this->logDebug('OTHER ERROR');
         }
     });
 }
コード例 #2
0
/**
 * @param Promise $promise
 * @param float                    $timeoutInSeconds
 *
 * @return Promise
 */
function timeout($promise, $timeoutInSeconds = 3.0)
{
    global $container;
    return \React\Promise\Timer\timeout($promise, $timeoutInSeconds, $container['loop']);
}