addDelay() public method

Add delay.
public addDelay ( integer $time ) : React\Promise\PromiseInterface
$time integer
return React\Promise\PromiseInterface
Ejemplo n.º 1
0
Archivo: Co.php Proyecto: mpyw/co
 /**
  * Handle resolving generators still running.
  * @param  GeneratorContainer $gc
  * @return PromiseInterface
  */
 private function processGeneratorContainerRunning(GeneratorContainer $gc)
 {
     // Check delay request yields
     if ($gc->key() === CoInterface::DELAY) {
         return $this->pool->addDelay($gc->current())->then(function () use($gc) {
             $gc->send(null);
             return $this->processGeneratorContainer($gc);
         });
     }
     // Now we normalize yielded value
     $yielded = YieldableUtils::normalize($gc->current());
     $yieldables = YieldableUtils::getYieldables($yielded, [], $this->runners);
     if (!$yieldables) {
         // If there are no yieldables, send yielded value back into generator
         $gc->send($yielded);
         // Continue
         return $this->processGeneratorContainer($gc);
     }
     // Chain resolver
     return $this->promiseAll($yieldables, $gc->key() !== CoInterface::SAFE)->then(YieldableUtils::getApplier($yielded, $yieldables, [$gc, 'send']), [$gc, 'throw_'])->then(function () use($gc, $yieldables) {
         // Continue
         $this->runners = array_diff_key($this->runners, $yieldables);
         return $this->processGeneratorContainer($gc);
     });
 }
Ejemplo n.º 2
0
 public function testWaitCurlAndDelay()
 {
     $pool = new Pool(new CoOption(['concurrency' => 3]));
     $pool->addCurl(new DummyCurl('A', 10))->then(function () use(&$x) {
         $x = microtime(true);
     });
     $pool->addDelay(1.3)->then(function () use(&$y) {
         $y = microtime(true);
     });
     $pool->addDelay(1.1)->then(function () use(&$z) {
         $z = microtime(true);
     });
     $pool->addDelay(1.2)->then(function () use(&$w) {
         $w = microtime(true);
     });
     $pool->wait();
     $this->assertNotNull($x);
     $this->assertNotNull($y);
     $this->assertNotNull($z);
     $this->assertNotNull($w);
     $this->assertTrue($x < $z);
     $this->assertTrue($z < $w);
     $this->assertTrue($w < $y);
 }
Ejemplo n.º 3
0
Archivo: PoolTest.php Proyecto: mpyw/co
 public function testInvalidDelayDomain()
 {
     $pool = new Pool(new CoOption(['concurrency' => 3]));
     $this->setExpectedException(\DomainException::class);
     $pool->addDelay(-1, new Deferred());
 }