Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HttpClient] Async HTTPlug client #33743

Merged
merged 1 commit into from Oct 7, 2019

Conversation

Nyholm
Copy link
Member

@Nyholm Nyholm commented Sep 27, 2019

Q A
Branch? 4.4
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #33710, Fix #32142
License MIT
Doc PR symfony/symfony-docs#12389

This PR removes HttplugClient's dependency on Psr18Client. It will also add an HttplugPromise to make sure we sure we respect the Httplug's HttpAsyncClient interface.

It implements HttpAsyncClient::sendAsyncRequest() and provides two extensions:

  • HttplugPromise::cancel() allows cancelling a promise (and the underlying response)
  • HttplugClient::wait() allows to tick the promise pool, with configurable timeouts.

Copy link
Member Author

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied some code from Psr18Client. If someone got suggestion how to share code between Psr18Client, HttplugClient and CorePromise Im happy to update this PR.

src/Symfony/Component/HttpClient/Httplug/CorePromise.php Outdated Show resolved Hide resolved
src/Symfony/Component/HttpClient/HttplugClient.php Outdated Show resolved Hide resolved
@Nyholm Nyholm force-pushed the async-http-client branch 2 times, most recently from f647abe to 02d7aac Compare September 28, 2019 16:27
@nicolas-grekas nicolas-grekas added this to the next milestone Sep 29, 2019
@nicolas-grekas nicolas-grekas force-pushed the async-http-client branch 10 times, most recently from 5e63313 to 0cbe120 Compare October 3, 2019 21:20
nicolas-grekas
nicolas-grekas previously approved these changes Oct 3, 2019
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed on Slack, I rewrote the promise part: the previous logic was copied from https://github.com/php-http/curl-client/blob/master/src/PromiseCore.php yet the logic there is completely broken (see php-http/curl-client#59 and unlike guzzle6-adapter which uses Guzzle promises and thus works as expected.)

The new HttplugPromise implements the correct logic (hopefuly ;) ), has a cancel() method and is compatible with Guzzle promises.

Copy link
Member Author

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found two small things. I’ll continue test running this code tomorrow.

@nicolas-grekas nicolas-grekas force-pushed the async-http-client branch 2 times, most recently from 1444872 to 067ffcd Compare October 4, 2019 06:41
Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR is ready.

It implements HttpAsyncClient::sendAsyncRequest() and provides two extensions:

  • HttplugPromise::cancel() allows cancelling a promise (and the underlying response)
  • HttplugClient::wait() allows to tick the promise pool, with configurable timeouts.

@Nyholm
Copy link
Member Author

Nyholm commented Oct 6, 2019

I pushed two small bugfixes. Im happy with this PR now

@nicolas-grekas
Copy link
Member

Thank you @Nyholm.

@nicolas-grekas nicolas-grekas merged commit 4fd593f into symfony:4.4 Oct 7, 2019

public function cancel(): void
{
$this->promise->cancel();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this also call the cancel callback ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the guzzle promise will call it already

@Nyholm Nyholm deleted the async-http-client branch October 7, 2019 21:20
nicolas-grekas added a commit that referenced this pull request Oct 12, 2019
…() (nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[HttpClient] resolve promise chains on HttplugClient::wait()

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #32142
| License       | MIT
| Doc PR        | -

Follow up of #33743

Right now, keeping a reference to promise objects returned by `HttplugClient::sendAsyncRequest()`, then calling their `wait()` method is the only way to actually resolve the promises. That's why when these promises are destructed, we cancel the corresponding HTTP request.

But thanks to the `HttplugClient::wait()` method, we have a hook to tick the event loop managed by the Symfony client.

I added a test case to run into this situation.

~It fails currently. I'd like asking @joelwurtz, @dbu and/or maybe @Nyholm if you could have a look and finish this PR? I'm not that familiar with promises and you might get faster and better to the goal. Anyone else is welcome also of course. Thank you for having a look :) PR welcome on my fork or as a separate one on this repos.~

Commits
-------

ea0be07 [HttpClient] resolve promise chains on HttplugClient::wait()
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.4 Oct 27, 2019
OskarStark added a commit to symfony/symfony-docs that referenced this pull request Nov 1, 2019
…holm, nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

Adapted the HTTPlug integration docs to Async Client

This should be merged with symfony/symfony#33743

Closes #12472
Closes #12475

Commits
-------

d353b61 Complete doc for 4.4 features
7295404 Adapted the HTTPlug integration docs to Async Client
This was referenced Nov 12, 2019
fabpot added a commit that referenced this pull request Nov 19, 2019
…ntation (Taluu)

This PR was merged into the 4.4 branch.

Discussion
----------

States that the HttpClient provides a Http Async implementation

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no (not really)
| New feature?  | no (not really)
| Deprecations? | no
| Tickets       | ~
| License       | MIT
| Doc PR        | ~

Add in the composer.json of the HttpClient that it now provides an implementation for the `php-http/async-client-implementation` virtual package, as @Nyholm did the implementation on the HttpPlug bridge in #33743.

Commits
-------

8a460ce States that the HttpClient provides a Http Async implementation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[HttpClient] implement async client [HttpClient] Getting responses asynchronously as soon as they ready
5 participants