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
Update WebSocket examples #713
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4230,7 +4230,10 @@ promises returned by its <a lt="writable stream writer">writer</a>'s {{WritableS | |
|
||
return new WritableStream({ | ||
start(controller) { | ||
ws.onerror = () => controller.error(new Error("The WebSocket errored!")); | ||
ws.onerror = () => { | ||
controller.error(new Error("The WebSocket errored!")); | ||
ws.onclose = null; | ||
}; | ||
ws.onclose = () => controller.error(new Error("The server closed the connection unexpectedly!")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If for example the remote server closes the connection abruptly, then onerror and onclose will both fire. I don't actually know of a case where onerror fires without onclose also firing. Certainly Chrome's implementation never does it. So one way of simplifying this would just be to not set an onerror handler. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to check my understanding, the server could close it non-abruptly, right? In which case close would fire but not error. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, so this definitely needs to be fixed since you can't call controller.error() twice. Not sure about the best way to do that while balancing:
Will noodle on it. |
||
return new Promise(resolve => ws.onopen = resolve); | ||
}, | ||
|
@@ -4386,6 +4389,7 @@ source abstractions. | |
this._ws.onclose = () => controller.error(new Error("The server closed the connection unexpectedly!")); | ||
this._ws.addEventListener("error", () => { | ||
controller.error(new Error("The WebSocket errored!")); | ||
this._ws.onclose = null; | ||
}); | ||
|
||
return new Promise(resolve => this._ws.onopen = resolve); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So does this overall LGTY now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. lgtm.