@@ -27,7 +27,12 @@ public class Engine {
2727 ///
2828 /// Engine must be running for `send(command:)` to work.
2929 public private( set) var isRunning = false
30-
30+
31+ private let queue = DispatchQueue (
32+ label: " ck-engine-queue " ,
33+ qos: . userInteractive
34+ )
35+
3136 /// Initializes an engine with the provided `type`.
3237 ///
3338 /// - parameter type: The type of engine to use.
@@ -40,11 +45,13 @@ public class Engine {
4045 messenger. responseHandler = { [ weak self] response in
4146 guard let self else { return }
4247
43- if let parsedResponse = EngineResponse ( rawValue: response) {
44- self . log ( parsedResponse. rawValue)
45- self . receiveResponse ( parsedResponse)
46- } else if !response. isEmpty {
47- self . log ( response)
48+ DispatchQueue . main. async {
49+ if let parsedResponse = EngineResponse ( rawValue: response) {
50+ self . log ( parsedResponse. rawValue)
51+ self . receiveResponse ( parsedResponse)
52+ } else if !response. isEmpty {
53+ self . log ( response)
54+ }
4855 }
4956 }
5057 }
@@ -110,9 +117,11 @@ public class Engine {
110117 log ( " Engine is not running, call start() first. " )
111118 return
112119 }
113-
114- log ( command. rawValue)
115- messenger. sendCommand ( command. rawValue)
120+
121+ queue. async {
122+ self . log ( command. rawValue)
123+ self . messenger. sendCommand ( command. rawValue)
124+ }
116125 }
117126
118127 /// Closure that is called when engine responses are received.
0 commit comments