@@ -177,15 +177,20 @@ registerNewDebugSession
177
177
:: SessionId
178
178
-> app
179
179
-> Adaptor app ()
180
+ -- ^ Action to run debugger (operates in a forked thread that gets killed when disconnect is set)
181
+ -> Adaptor app ()
180
182
-- ^ Long running operation, meant to be used as a sink for
181
183
-- the debugger to emit events and for the adaptor to forward to the editor
182
184
-- This function should be in a 'forever' loop waiting on the read end of
183
185
-- a debugger channel.
184
186
-> Adaptor app ()
185
- registerNewDebugSession k v action = do
187
+ registerNewDebugSession k v debuggerExecution outputEventSink = do
186
188
store <- gets appStore
187
- tid <- fork (resetAdaptorStatePayload >> action)
188
- liftIO . atomically $ modifyTVar' store (H. insert k (tid, v))
189
+ debuggerThreadState <-
190
+ DebuggerThreadState
191
+ <$> fork (debuggerExecution)
192
+ <*> fork (outputEventSink)
193
+ liftIO . atomically $ modifyTVar' store (H. insert k (debuggerThreadState, v))
189
194
setDebugSessionId k
190
195
logInfo $ BL8. pack $ " Registered new debug session: " <> unpack k
191
196
----------------------------------------------------------------------------
@@ -194,7 +199,7 @@ getDebugSession = do
194
199
(_, _, app) <- getDebugSessionWithThreadIdAndSessionId
195
200
pure app
196
201
----------------------------------------------------------------------------
197
- getDebugSessionWithThreadIdAndSessionId :: Adaptor app (SessionId , ThreadId , app )
202
+ getDebugSessionWithThreadIdAndSessionId :: Adaptor app (SessionId , DebuggerThreadState , app )
198
203
getDebugSessionWithThreadIdAndSessionId = do
199
204
sessionId <- getDebugSessionId
200
205
appStore <- liftIO . readTVarIO =<< getAppStore
@@ -217,10 +222,11 @@ getDebugSessionWithThreadIdAndSessionId = do
217
222
----------------------------------------------------------------------------
218
223
destroyDebugSession :: Adaptor app ()
219
224
destroyDebugSession = do
220
- (sessionId, tid , app) <- getDebugSessionWithThreadIdAndSessionId
225
+ (sessionId, DebuggerThreadState { .. } , app) <- getDebugSessionWithThreadIdAndSessionId
221
226
store <- getAppStore
222
227
liftIO $ do
223
- killThread tid
228
+ killThread debuggerThread
229
+ killThread debuggerOutputEventThread
224
230
atomically $ modifyTVar' store (H. delete sessionId)
225
231
logInfo $ BL8. pack $ " SessionId " <> unpack sessionId <> " ended"
226
232
----------------------------------------------------------------------------
0 commit comments