Exemple #1
0
 public function testCurlWithoutDeferred()
 {
     $pool = new Pool(new CoOption());
     $pool->addCurl(new DummyCurl('valid', 1));
     $pool->addCurl(new DummyCurl('invalid', 1, true));
     $pool->wait();
     $this->assertTrue(true);
 }
Exemple #2
0
 public function testUnlimitedConcurrency()
 {
     $pool = new Pool(new CoOption(['concurrency' => 0, 'autoschedule' => true]));
     $curls = [];
     foreach (range(1, 100) as $i) {
         $curls[] = new DummyCurl($i, 2);
     }
     $done = [];
     foreach ($curls as $ch) {
         $pool->addCurl($ch)->then(function ($result) use(&$done) {
             $done[] = $result;
         }, function () {
             $this->assertTrue(false);
         });
     }
     $pool->wait();
     foreach ($curls as $curl) {
         $str = str_replace('DummyCurl', 'Response', (string) $curl);
         $this->assertContains($str, $done);
         $this->assertEquals([0, 2], [$curl->startedAt(), $curl->stoppedAt()]);
     }
 }
Exemple #3
0
Fichier : Co.php Projet : mpyw/co
 /**
  * Promise all changes in yieldables are prepared.
  * @param  array $yieldables
  * @param  bool  $throw_acceptable
  * @return PromiseInterface
  */
 private function promiseAll(array $yieldables, $throw_acceptable)
 {
     $promises = [];
     foreach ($yieldables as $yieldable) {
         // Add or enqueue cURL handles
         if (TypeUtils::isCurl($yieldable['value'])) {
             $promises[(string) $yieldable['value']] = $this->pool->addCurl($yieldable['value']);
             continue;
         }
         // Process generators
         if (TypeUtils::isGeneratorContainer($yieldable['value'])) {
             $promises[(string) $yieldable['value']] = $this->processGeneratorContainer($yieldable['value']);
             continue;
         }
     }
     // If caller cannot accept exception,
     // we handle rejected value as resolved.
     if (!$throw_acceptable) {
         $promises = array_map(['\\mpyw\\Co\\Internal\\YieldableUtils', 'safePromise'], $promises);
     }
     return \React\Promise\all($promises);
 }