@@ -19,6 +19,7 @@ public class Server<InitPayload: Equatable & Codable> {
19
19
var auth : ( InitPayload ) throws -> Void = { _ in }
20
20
var onExit : ( ) -> Void = { }
21
21
var onMessage : ( String ) -> Void = { _ in }
22
+ var onStop : ( ) -> Void = { }
22
23
23
24
var initialized = false
24
25
@@ -66,6 +67,7 @@ public class Server<InitPayload: Equatable & Codable> {
66
67
return
67
68
}
68
69
70
+ // handle incoming message
69
71
switch request. type {
70
72
case . GQL_CONNECTION_INIT:
71
73
guard let connectionInitRequest = try ? self . decoder. decode ( ConnectionInitRequest< InitPayload> . self , from: json) else {
@@ -116,6 +118,12 @@ public class Server<InitPayload: Equatable & Codable> {
116
118
self . onMessage = callback
117
119
}
118
120
121
+ /// Define the callback run on receipt of a`GQL_STOP` message
122
+ /// - Parameter callback: The callback to assign
123
+ public func onStop( _ callback: @escaping ( ) -> Void ) {
124
+ self . onStop = callback
125
+ }
126
+
119
127
private func onConnectionInit( _ connectionInitRequest: ConnectionInitRequest < InitPayload > , _ messenger: Messenger ) {
120
128
guard !initialized else {
121
129
self . error ( . tooManyInitializations( ) )
@@ -206,6 +214,7 @@ public class Server<InitPayload: Equatable & Codable> {
206
214
self . error ( . notInitialized( ) )
207
215
return
208
216
}
217
+ onStop ( )
209
218
}
210
219
211
220
private func onConnectionTerminate( _: ConnectionTerminateRequest , _ messenger: Messenger ) {
0 commit comments