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

Return the result of send() #91

Merged
merged 1 commit into from
Jan 25, 2019
Merged

Return the result of send() #91

merged 1 commit into from
Jan 25, 2019

Conversation

hhxsv5
Copy link
Contributor

@hhxsv5 hhxsv5 commented Jan 22, 2019

No description provided.

@mbonneau mbonneau merged commit b06df34 into ratchetphp:master Jan 25, 2019
@mbonneau
Copy link
Member

@hhxsv5 - Thanks for this catch. I will tag a new release shortly.

@hhxsv5
Copy link
Contributor Author

hhxsv5 commented Jan 25, 2019

@mbonneau Nice! You are welcome.

@clue
Copy link
Member

clue commented Jan 25, 2019

@hhxsv5 What is the motivation for this change?

It's my understanding the current API mimics Browser's WebSocket API, which doesn't return anything either, no?

@hhxsv5
Copy link
Contributor Author

hhxsv5 commented Jan 25, 2019

I just want to know if the send operation is successful or if there are any errors. like gorilla/websocket @clue

@clue
Copy link
Member

clue commented Jan 25, 2019

The underlying write() method does not return a "succesful" status. It only returns whether the given data could be added to the buffer or whether the client should pause sending data before the buffer is drained, see also https://github.com/reactphp/stream#write.

I understand where you're coming from and it looks like your request would be best addressed when #88 is resolved.

In the meantime, I would argue that this patch is counterproductive.

@mbonneau
Copy link
Member

@clue Isn't letting the user know if they should pause sending valuable enough to return?

@hhxsv5
Copy link
Contributor Author

hhxsv5 commented Jan 25, 2019

@clue I understand your concerns, it doesn't matter. If the return value does not represent the actual result of the call, specify it in the comment or document. Here I recommend returning the value of write.

@clue
Copy link
Member

clue commented Jan 25, 2019

@mbonneau I agree that this provides some value, but I'm not sure this is how higher-level implementations actually (ought to) use this.

It's my understanding the current API mimics Browser's WebSocket API, which doesn't return anything either. In particular, the WebSocket::send() usually buffers by default and will close the socket with a fatal error if the buffer size is exceeded. Depending on how you want this project's API to be used, this may or may not make sense here as well. I agree that this is something that should be discussed (perhaps outside of this ticket).

IMHO returning a boolean in this higher-level implementation is misleading and might give a false sense of "succesful" writes. This being an async implementation means that "unsuccessful" writes may only be detected at a later time, e.g. when the socket reports an error etc.

@mbonneau
Copy link
Member

@clue I was considering that this may be useful for flow control - but to do that we would need to know when it is ok to send again, which the API gives no access to. This makes that return value less important.

I could go either way as I don't think there is anything more useful to return.

@clue
Copy link
Member

clue commented Jan 27, 2019

@mbonneau No objections, didn't mean to block this change. It's still my understanding that this return value might be confusing for people not intimately familiar with the underlying stream abstraction, but I guess some good documentation might help mitigate this 👍

@clue clue mentioned this pull request Apr 6, 2020
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.

None yet

3 participants