@@ -28,31 +28,31 @@ import GraphQLWS
2828class WebSocketMessenger : Messenger {
2929 private weak var websocket: WebSocket?
3030 private var onReceive: (String ) -> Void = { _ in }
31-
31+
3232 init (websocket : WebSocket) {
3333 self .websocket = websocket
3434 websocket.onText { _ , message in
35- self .onReceive (message)
35+ try await self .onReceive (message)
3636 }
3737 }
38-
39- func send <S >(_ message : S) where S: Collection , S.Element == Character {
38+
39+ func send <S >(_ message : S) async throws where S: Collection , S.Element == Character async throws {
4040 guard let websocket = websocket else { return }
41- websocket.send (message)
41+ try await websocket.send (message)
4242 }
43-
44- func onReceive (callback : @escaping (String ) -> Void ) {
43+
44+ func onReceive (callback : @escaping (String ) async throws -> Void ) {
4545 self .onReceive = callback
4646 }
47-
48- func error (_ message : String , code : Int ) {
47+
48+ func error (_ message : String , code : Int ) async throws {
4949 guard let websocket = websocket else { return }
50- websocket.send (" \( code ) : \( message ) " )
50+ try await websocket.send (" \( code ) : \( message ) " )
5151 }
52-
53- func close () {
52+
53+ func close () async throws {
5454 guard let websocket = websocket else { return }
55- _ = websocket.close ()
55+ try await websocket.close ()
5656 }
5757}
5858```
@@ -67,7 +67,7 @@ routes.webSocket(
6767 let server = GraphQLWS.Server < EmptyInitPayload?> (
6868 messenger : messenger,
6969 onExecute : { graphQLRequest in
70- api.execute (
70+ try await api.execute (
7171 request : graphQLRequest.query ,
7272 context : context,
7373 on : self .eventLoop ,
@@ -76,7 +76,7 @@ routes.webSocket(
7676 )
7777 },
7878 onSubscribe : { graphQLRequest in
79- api.subscribe (
79+ try await api.subscribe (
8080 request : graphQLRequest.query ,
8181 context : context,
8282 on : self .eventLoop ,
@@ -128,8 +128,8 @@ If the `payload` field is not required on your server, you may make Server's gen
128128
129129## Memory Management
130130
131- Memory ownership among the Server, Client, and Messenger may seem a little backwards. This is because the Swift/Vapor WebSocket
132- implementation persists WebSocket objects long after their callback and they are expected to retain strong memory references to the
131+ Memory ownership among the Server, Client, and Messenger may seem a little backwards. This is because the Swift/Vapor WebSocket
132+ implementation persists WebSocket objects long after their callback and they are expected to retain strong memory references to the
133133objects required for responses. In order to align cleanly and avoid memory cycles, Server and Client are injected strongly into Messenger
134134callbacks, and only hold weak references to their Messenger. This means that Messenger objects (or their enclosing WebSocket) must
135135be persisted to have the connected Server or Client objects function. That is, if a Server's Messenger falls out of scope and deinitializes,
0 commit comments