addCurl() 공개 메소드

Call curl_multi_add_handle() or push into queue.
public addCurl ( resource $ch ) : React\Promise\PromiseInterface
$ch resource
리턴 React\Promise\PromiseInterface
예제 #1
0
파일: PoolTest.php 프로젝트: mpyw/co
 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);
 }
예제 #2
0
파일: Co.php 프로젝트: 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);
 }
예제 #3
0
파일: AutoPoolTest.php 프로젝트: mpyw/co
 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()]);
     }
 }