Skip to content

Commit

Permalink
feat(runtime): cancel all handlers instead of just the main one
Browse files Browse the repository at this point in the history
  • Loading branch information
symbiont-stevan-andjelkovic committed Apr 29, 2021
1 parent a96fe21 commit 46567c1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/runtime-prototype/src/StuntDouble/EventLoop.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ newtype EventLoopRef = EventLoopRef
initLoopState :: Transport IO -> IO LoopState
initLoopState transport =
LoopState
<$> newEmptyTMVarIO
<$> newTVarIO []
<*> newTBQueueIO 128
<*> newTVarIO Map.empty
<*> newTVarIO Map.empty
Expand All @@ -40,11 +40,11 @@ initLoopState transport =
makeEventLoop :: FilePath -> IO EventLoopRef
makeEventLoop fp = do
transport <- namedPipeTransport fp
loopState <- initLoopState transport
aReqHandler <- async (handleRequests loopState)
a <- async (handleEvents loopState)
atomically (putTMVar (loopStateAsync loopState) a)
return (EventLoopRef loopState)
ls <- initLoopState transport
aReqHandler <- async (handleRequests ls)
aEvHandler <- async (handleEvents ls)
atomically (modifyTVar' (loopStatePids ls) ([aReqHandler, aEvHandler] ++ ))
return (EventLoopRef ls)

handleEvents :: LoopState -> IO ()
handleEvents ls = go
Expand Down Expand Up @@ -75,9 +75,9 @@ handleCommand (Send rr m) ls = do
-- atomically (modifyTVar (loopStateAsyncs ls) (a :))
undefined
handleCommand Quit ls = do
a <- atomically (takeTMVar (loopStateAsync ls))
pids <- atomically (readTVar (loopStatePids ls))
threadDelay 100000
cancel a
mapM_ cancel pids

data ActorNotFound = ActorNotFound RemoteRef
deriving Show
Expand Down
3 changes: 2 additions & 1 deletion src/runtime-prototype/src/StuntDouble/EventLoop/State.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import StuntDouble.Message


data LoopState = LoopState
{ loopStateAsync :: TMVar (Async ()) -- | Hold the `Async` of the event loop itself.
{ loopStatePids :: TVar [Async ()] -- | Holds the `Async`s (or PIDs) of the
-- event loop itself.
, loopStateQueue :: TBQueue Event
, loopStateActors :: TVar (Map LocalRef (Message -> Actor)) -- XXX: Only changed by main loop, so no need for STM?
-- , loopStateHandlers :: TVar (Map (Async Message) (Message -> Actor))
Expand Down

0 comments on commit 46567c1

Please sign in to comment.