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

Added note about async non-goal #31

Closed
wants to merge 2 commits into from
Closed

Added note about async non-goal #31

wants to merge 2 commits into from

Conversation

Nyholm
Copy link
Member

@Nyholm Nyholm commented Aug 12, 2017

This will fix #29

#### Asynchronous HTTP client

The reason asynchronous support is a non-goal is because a PSR for HTTP clients
should not define Promises. That should be a separate PSR. Waiting for a such PSR
Copy link

Choose a reason for hiding this comment

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

should define neither promises nor an async-compatible version of PSR-7

Copy link
Member Author

Choose a reason for hiding this comment

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

Can you tell me why PSR-7 is not async?

Copy link

Choose a reason for hiding this comment

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

For example, because getContents() requires blocking, as does __toString().

Copy link
Member Author

Choose a reason for hiding this comment

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

That is an implementation detail. ;)

Copy link

Choose a reason for hiding this comment

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

No, it's not. Blocking is an absolute no-go in fully async apps.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nowhere in the PSR-7 specification does it say that getContents has to use __toString. (In fact getContents and __toString has different behaviours. ) Nor does it say that it has to be blocking.

Im saying that you can implement PSR-7 with non-blocking. It is not a limitation in the interface but in the implementations.

Copy link

Choose a reason for hiding this comment

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

Of course it doesn't say it has to be blocking, as that's the default for any IO operation in PHP. It has to be blocking, because the interface requires an immediate return on a call to these methods.

Im saying that you can implement PSR-7 with non-blocking.

Could you try to elaborate how that should be possible? See what React did.

Copy link

Choose a reason for hiding this comment

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

I agree with @Nyholm here, the text LGTM and the discussion whether PSR-7 can be used in an async context is both an implementation detail and out of scope here 👍

(@kelunik IMO the last link adds little value here and its motivation is better described in the documentation (https://github.com/reactphp/http#request), rather than the code. As an alternative, PSR-7 does not prevent you from buffering the whole message in memory, in which case all accessors can be used perfectly fine even in an async program 👍)

Copy link

Choose a reason for hiding this comment

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

@clue It doesn't really matter as an async client is out of scope in any way, regardless of the wording here.

I completely understand the motivation behind that, but it doesn't really matter either. If it could be implemented sanely, I'm pretty sure you guys would have done that. It doesn't prevent buffering, of course not, but we both know that it doesn't fit for all bodies and is the exact reason why the request body isn't represented as a string, but a stream.

@sagikazarmark
Copy link
Member

I agree with @Nyholm although I think we could improve this section a bit.

Here are some thoughts:

Asynchronous HTTP clients are often implemented using Promises. While a promise interface could be part of this PSR, that could delay the release of this PSR for years. Also, there is a group already working on a separate PSR for promises which could be used in a future Async HTTP client PSR.

For these reasons we decided to ... blahblah

@Nyholm can you please play with this section a bit more? See what comes out of it.

@kelunik
Copy link

kelunik commented Sep 4, 2017

A promise interface should definitely not be part of an HTTP client PSR.

Copy link

@dbu dbu left a comment

Choose a reason for hiding this comment

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

i added one suggestion to add a bit of the discussion we had on a separate interface for async requests. if we are happy with that lets add it and merge?


The reason asynchronous support is a non-goal is because a PSR for HTTP clients
should not define Promises. That should be a separate PSR. Waiting for a such PSR
could postpone a HTTP client PSR with years.
Copy link

Choose a reason for hiding this comment

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

lets maybe formulate this more neutral "would delay the HTTP client PSR." and then add "A separate interface for asynchronous requests can be defined in a separate PSR once the promise PSR is accepted. The method signature for asynchronous requests has to be different."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Asynchronous requests
5 participants