File tree Expand file tree Collapse file tree 2 files changed +36
-4
lines changed Expand file tree Collapse file tree 2 files changed +36
-4
lines changed Original file line number Diff line number Diff line change @@ -289,8 +289,8 @@ func WebsocketCloseSprintf(format string, vars ...any) string {
289
289
// open a workspace in multiple tabs, the entire UI can start to lock up.
290
290
// WebSockets have no such limitation, no matter what HTTP protocol was used to
291
291
// establish the connection.
292
- func OneWayWebSocket [T any ](rw http.ResponseWriter , r * http.Request ) (
293
- sendEvent func (wsEvent T ) error ,
292
+ func OneWayWebSocket [JsonSerializable any ](rw http.ResponseWriter , r * http.Request ) (
293
+ sendEvent func (event JsonSerializable ) error ,
294
294
closed chan struct {},
295
295
err error ,
296
296
) {
@@ -307,7 +307,7 @@ func OneWayWebSocket[T any](rw http.ResponseWriter, r *http.Request) (
307
307
Code websocket.StatusCode
308
308
Reason string
309
309
}
310
- eventC := make (chan T )
310
+ eventC := make (chan JsonSerializable )
311
311
socketErrC := make (chan SocketError , 1 )
312
312
closed = make (chan struct {})
313
313
go func () {
@@ -354,7 +354,7 @@ func OneWayWebSocket[T any](rw http.ResponseWriter, r *http.Request) (
354
354
}
355
355
}()
356
356
357
- sendEvent = func (event T ) error {
357
+ sendEvent = func (event JsonSerializable ) error {
358
358
select {
359
359
case eventC <- event :
360
360
case <- ctx .Done ():
Original file line number Diff line number Diff line change @@ -155,3 +155,35 @@ func TestWebsocketCloseMsg(t *testing.T) {
155
155
assert .Equal (t , len (trunc ), 123 )
156
156
})
157
157
}
158
+
159
+ func TestOneWayWebSocket (t * testing.T ) {
160
+ t .Parallel ()
161
+
162
+ t .Run ("Produces an error if the socket connection could not be established" , func (t * testing.T ) {
163
+ t .Parallel ()
164
+ })
165
+
166
+ t .Run ("Returned callback can publish a new event to the WebSocket connection" , func (t * testing.T ) {
167
+ t .Parallel ()
168
+ })
169
+
170
+ t .Run ("Signals to an outside consumer when the socket has been closed" , func (t * testing.T ) {
171
+ t .Parallel ()
172
+ })
173
+
174
+ t .Run ("Socket will automatically close if client sends a single message" , func (t * testing.T ) {
175
+ t .Parallel ()
176
+ })
177
+
178
+ t .Run ("Returned callback returns error if called after socket has been closed" , func (t * testing.T ) {
179
+ t .Parallel ()
180
+ })
181
+
182
+ t .Run ("Sends a heartbeat to the socket on a fixed internal of time to keep connections alive" , func (t * testing.T ) {
183
+ t .Parallel ()
184
+ })
185
+
186
+ t .Run ("Renders the socket inert if the parent context cancels" , func (t * testing.T ) {
187
+ t .Parallel ()
188
+ })
189
+ }
You can’t perform that action at this time.
0 commit comments