You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add ready promise and close reason
Adds a `socket.ready` promise that is resolved when the socket
connection has been established.
Adds an optional `reason` argument to `socket.close()` that is
to be forwarded on to the underlying `ReadableStream` and
`WritableStream` when they are canceled/aborted.
* Rename `ready` to `opened`
Additionally, the binding object does not necessarily have to be an instance of a class, nor does it even have to be JavaScript. It can be any mechanism that exposes the {{connect()}} method. Cloudflare achieves this through [environment bindings](https://developers.cloudflare.com/workers/configuration/bindings/).
66
+
Additionally, the binding object does not necessarily have to be an instance of a class, nor does it even have to be JavaScript. It can be any mechanism that exposes the {{connect()}} method. Cloudflare achieves this through [environment bindings](https://developers.cloudflare.com/workers/configuration/bindings/).
67
67
68
68
<h2 id="socket-section">Socket</h2>
69
69
@@ -94,8 +94,10 @@ interface Socket {
94
94
readonly attribute ReadableStream readable;
95
95
readonly attribute WritableStream writable;
96
96
97
+
readonly attribute Promise<undefined> opened;
98
+
97
99
readonly attribute Promise<undefined> closed;
98
-
Promise<undefined> close();
100
+
Promise<undefined> close(optional any reason);
99
101
100
102
[NewObject] Socket startTls();
101
103
};
@@ -154,6 +156,12 @@ The {{writable}} attribute is a {{WritableStream}} which sends data to the serve
154
156
</pre>
155
157
</div>
156
158
159
+
<h4 id="opened-attribute">opened</h4>
160
+
161
+
The {{opened}} attribute is a promise that is resolved when the socket connection has been
162
+
successfully established, or is rejected if the connection fails. For sockets use secure-transport,
163
+
the resolution of the {{opened}} promise indicates the completion of the secure handshake.
164
+
157
165
<h4 id="closed-attribute">closed</h4>
158
166
159
167
The {{closed}} attribute is a promise which can be used to keep track of the socket state. It gets resolved under the
@@ -165,7 +173,7 @@ following circumstances:
165
173
</ul>
166
174
167
175
<div class="note">
168
-
The current Cloudflare Workers implementation behaves as described above, specifically the
176
+
The current Cloudflare Workers implementation behaves as described above, specifically the
169
177
ReadableStream needs to be read until completion for the `closed` promise to resolve, if the
170
178
ReadableStream is not read then even if the server closes the connection the `closed` promise
171
179
will not resolve.
@@ -184,10 +192,14 @@ Cancelling the socket's ReadableStream and closing the socket's WritableStream d
184
192
185
193
<h3 id="methods">Methods</h3>
186
194
187
-
<h4 id="close-method">close()</h4>
195
+
<h4 id="close-method">close(optional any reason)</h4>
188
196
189
197
The {{close()}} method closes the socket and its underlying connection. It returns the same promise as the {{closed}} attribute.
190
198
199
+
When called, the {{ReadableStream}} and {{WritableStream}} associated with the {{Socket}} will
200
+
be canceled and aborted, respectively. If the {{reason}} argument is specified, the {{reason}}
201
+
will be passed on to both the {{ReadableStream}} and {{WritableStream}}.
202
+
191
203
<h4 id="starttls-method">startTls()</h4>
192
204
193
205
The {{startTls()}} method enables opportunistic TLS (otherwise known as [StartTLS](https://en.wikipedia.org/wiki/Opportunistic_TLS)) which is a requirement for some protocols (primarily postgres/mysql and other DB protocols).
@@ -284,7 +296,7 @@ At any point during the creation of the {{Socket}} instance, `connect` may throw
284
296
{{secureTransport}} member
285
297
</dt>
286
298
<dd>
287
-
The secure transport mode to use.
299
+
The secure transport mode to use.
288
300
<dl>
289
301
<dt>{{off}}</dt>
290
302
<dd>A connection is established in plain text.</dd>
0 commit comments