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); }
/** * Start resovling. * @param mixed $value * @param bool $wait * @param mixed $throw Used for Co::async() overrides. * @param mixed If $wait, return resolved value. */ private function start($value, $wait = true, $throw = null) { $return = null; // For convenience, all values are wrapped into generator $con = YieldableUtils::normalize($this->getRootGenerator($throw, $value, $return)); $promise = $this->processGeneratorContainerRunning($con); if ($promise instanceof ExtendedPromiseInterface) { // This is actually 100% true; just used for unwrapping Exception thrown. $promise->done(); } // We have to wait $return only if $wait if ($wait) { $this->pool->wait(); return $return; } }
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()]); } }