@@ -177,15 +177,20 @@ registerNewDebugSession
177177 :: SessionId
178178 -> app
179179 -> Adaptor app ()
180+ -- ^ Action to run debugger (operates in a forked thread that gets killed when disconnect is set)
181+ -> Adaptor app ()
180182 -- ^ Long running operation, meant to be used as a sink for
181183 -- the debugger to emit events and for the adaptor to forward to the editor
182184 -- This function should be in a 'forever' loop waiting on the read end of
183185 -- a debugger channel.
184186 -> Adaptor app ()
185- registerNewDebugSession k v action = do
187+ registerNewDebugSession k v debuggerExecution outputEventSink = do
186188 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))
189194 setDebugSessionId k
190195 logInfo $ BL8. pack $ " Registered new debug session: " <> unpack k
191196----------------------------------------------------------------------------
@@ -194,7 +199,7 @@ getDebugSession = do
194199 (_, _, app) <- getDebugSessionWithThreadIdAndSessionId
195200 pure app
196201----------------------------------------------------------------------------
197- getDebugSessionWithThreadIdAndSessionId :: Adaptor app (SessionId , ThreadId , app )
202+ getDebugSessionWithThreadIdAndSessionId :: Adaptor app (SessionId , DebuggerThreadState , app )
198203getDebugSessionWithThreadIdAndSessionId = do
199204 sessionId <- getDebugSessionId
200205 appStore <- liftIO . readTVarIO =<< getAppStore
@@ -217,10 +222,11 @@ getDebugSessionWithThreadIdAndSessionId = do
217222----------------------------------------------------------------------------
218223destroyDebugSession :: Adaptor app ()
219224destroyDebugSession = do
220- (sessionId, tid , app) <- getDebugSessionWithThreadIdAndSessionId
225+ (sessionId, DebuggerThreadState { .. } , app) <- getDebugSessionWithThreadIdAndSessionId
221226 store <- getAppStore
222227 liftIO $ do
223- killThread tid
228+ killThread debuggerThread
229+ killThread debuggerOutputEventThread
224230 atomically $ modifyTVar' store (H. delete sessionId)
225231 logInfo $ BL8. pack $ " SessionId " <> unpack sessionId <> " ended"
226232----------------------------------------------------------------------------
0 commit comments