Skip to content

Commit

Permalink
refactor(runtime): add first test for quit
Browse files Browse the repository at this point in the history
  • Loading branch information
symbiont-stevan-andjelkovic committed Apr 27, 2021
1 parent ebea069 commit cf07ec5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/runtime-prototype/src/StuntDouble/EventLoop.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ type AsyncRef = (Async Message, RequestId)

data Event = Command Command | Response Response

data EventLoopRef = EventLoopRef (Async ())
newtype EventLoopRef = EventLoopRef
{ loopRefLoopState :: LoopState }

data LoopState = LoopState
{ loopStateAsync :: TMVar (Async ()) -- | Hold the `Async` of the event loop itself.
Expand All @@ -48,7 +49,7 @@ makeEventLoop = do
-- tid' <- forkIO $ forever $ undefined loopState
a <- async (handleEvents loopState)
atomically (putTMVar (loopStateAsync loopState) a)
return (EventLoopRef a)
return (EventLoopRef loopState)

handleEvents :: LoopState -> IO ()
handleEvents ls = go
Expand All @@ -65,3 +66,11 @@ handleCommand :: Command -> LoopState -> IO ()
handleCommand Quit ls = do
a <- atomically (takeTMVar (loopStateAsync ls))
cancel a

quit :: EventLoopRef -> IO ()
quit r = atomically $
writeTBQueue (loopStateQueue (loopRefLoopState r)) (Command Quit)

test = do
r <- makeEventLoop
quit r

0 comments on commit cf07ec5

Please sign in to comment.