Replies: 2 comments 15 replies
-
Sounds like douplication of |
Beta Was this translation helpful? Give feedback.
3 replies
-
I for one would be interested to use the Socket API for STOMP connections in Cloudflare Pages. Regarding prior arts, there was also:
I guess WebTransport could be of interest as well. Is there some ETA for production ? |
Beta Was this translation helpful? Give feedback.
12 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
@dom96 has been working on the implementation of a new Socket API for workerd that is a continuation of some exploratory spec work I started last year.
Our goal is to create a spec of this API with the hope that it will be implementable not only in workerd but also other runtimes such as Node.js, Deno, and Bun. This discussion will serve as the starting point for that specification.
Details
The API is modeled closely after the socket API that Deno has already implemented, however with a few key differences:
First the connect operation:
Socket
instance directly, rather than a Promise for a Socket, allows us to optimistically begin queing up writes and reads on the socket while it is being established, reducing overall latency. Since the underlying streams implementation is also async, we can rely on those mechanisms to determine when the streams are actually ready to receive and transmit.The abstract interface definition for a
Socket
is:The
Socket
instance would support being half-closed in manner similar to Node.js' API, specifically, when the writable side is closed, theSocket
will immediately send afin
after draining its pending write queue. TheSocket
will become half-closed, waiting for the readable side to receive afin
from the peer, which will close the readable side. Once both the writable and readable side are closed, theSocket
will close.We would support an
allowHalfOpen
option in the same manner as Node.js. WhenallowHalfOpen
isfalse
, the writable side of the socket is automatically closed when the readable side receives afin
from the peer. Any writes pending in the writable side queue are permitted to drain before closing the writable side. This will be the default behavior, just as it is in Node.js. WhenallowHalfOpen
istrue
, the writable side will not be automatically ended in response to receiving afin
on the readable side. Instead, user code must explicitly close the writable itself in order to send thefin
.The
Socket
will support an immediate destruction option usingdestroy()
, which will terminate both the readable and writable sides immediately, canceling pending reads and writes and closing both streams. Thedestroy()
method itself is not awaitable.For both the graceful and immediately destroy options, user code can optionally await the
closed
promise to determine when the socket is fully terminated and closed.Global
connect()
?Our current implementation adds
connect()
as a global as a property of specific configurable "binding" objects. We are not yet settled on whether introducing a new global method is the right thing to do.Beta Was this translation helpful? Give feedback.
All reactions