コード例 #1
0
ファイル: AckTest.php プロジェクト: omissis/stomp
 /** @test */
 public function itShouldReceiveAgainNackedMessages()
 {
     $loop = $this->getEventLoop();
     $client1 = $this->getClient($loop);
     $client2 = $this->getClient($loop);
     $counter = 0;
     When::all(array($client1->connect(), $client2->connect()), function () use($client1, $client2, $loop, &$counter) {
         $callback = function ($frame, $resolver) use($loop, &$counter) {
             if (0 === $counter) {
                 $resolver->nack();
             } else {
                 $resolver->ack();
                 $loop->stop();
             }
             $counter++;
         };
         $client1->subscribeWithAck('/topic/foo', 'client-individual', $callback);
         $client2->subscribeWithAck('/topic/foo', 'client-individual', $callback);
         $client1->send('/topic/foo', 'le message à la papa');
     });
     $loop->run();
     $this->assertEquals(2, $counter);
 }
コード例 #2
0
ファイル: Client.php プロジェクト: Sitronik/php-socks
 public function getConnection($host, $port)
 {
     if (strlen($host) > 255 || $port > 65535 || $port < 0) {
         return When::reject(new InvalidArgumentException('Invalid target specified'));
     }
     $deferred = new Deferred();
     $timestampTimeout = microtime(true) + $this->timeout;
     $timerTimeout = $this->loop->addTimer($this->timeout, function () use($deferred) {
         $deferred->reject(new Exception('Timeout while connecting to socks server'));
         // TODO: stop initiating connection and DNS query
     });
     // create local references as these settings may change later due to its async nature
     $auth = $this->auth;
     $protocolVersion = $this->protocolVersion;
     // protocol version not explicitly set?
     if ($protocolVersion === null) {
         // authentication requires SOCKS5, otherwise use SOCKS4a
         $protocolVersion = $auth === null ? '4a' : '5';
     }
     $loop = $this->loop;
     $that = $this;
     When::all(array($this->connector->create($this->socksHost, $this->socksPort)->then(null, function ($error) {
         throw new Exception('Unable to connect to socks server', 0, $error);
     }), $this->resolve($host)->then(null, function ($error) {
         throw new Exception('Unable to resolve remote hostname', 0, $error);
     })), function ($fulfilled) use($deferred, $port, $timestampTimeout, $that, $loop, $timerTimeout, $protocolVersion, $auth) {
         $loop->cancelTimer($timerTimeout);
         $timeout = max($timestampTimeout - microtime(true), 0.1);
         $deferred->resolve($that->handleConnectedSocks($fulfilled[0], $fulfilled[1], $port, $timeout, $protocolVersion, $auth));
     }, function ($error) use($deferred, $loop, $timerTimeout) {
         $loop->cancelTimer($timerTimeout);
         $deferred->reject(new Exception('Unable to connect to socks server', 0, $error));
     });
     return $deferred->promise();
 }
コード例 #3
0
ファイル: DaZeusAsync.php プロジェクト: dazeus/dazeus-php
 /**
  * {@inheritdoc}
  */
 public function unsubscribe($event, $callback)
 {
     $events = explode(' ', strtoupper($event));
     $promises = [];
     foreach ($events as $event) {
         $promises[] = $this->unsubscribeSingle($event, $callback);
     }
     return When::all($promises, function ($results) {
         foreach ($results as $result) {
             if ($result === false) {
                 return false;
             }
         }
         return true;
     });
 }