Skip to content

requestEnd() is not called in event listener in sync mode. #352

Description

@whataboutpereira

I converted my timings collector (based on LogHttpArchive) to the new events system and requestEnd() doesn't get called when the last request has finished.

$client = (new Amp\Http\Client\HttpClientBuilder)
    ->usingPool(Amp\Http\Client\Connection\ConnectionLimitingPool::byAuthority(4))
    ->listen(new HttpRequestTimings)
    ->build();

$semaphore = new Amp\Sync\LocalSemaphore(4);

$futures = [];

foreach ($urls as $url) {
	$futures[] = async(function () use ($client, $semaphore, $url) {
		$request = new Request($url);
		$lock = $semaphore->acquire();
		$response = $client->request($request)->getBody()->buffer();
		$lock->release();
	});
}

await($futures);

At this stage requestEnd() has not been called.

However if I add \Amp\delay(0) after await($futures), then requestEnd() is called.

Is this as intended? Should I somehow await for the HTTP client to finish?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions