@@ -42,11 +42,10 @@ import Duct.Context
42------------------------------------------------------------------------------
42------------------------------------------------------------------------------
44-- | Continue execution of the closure that we were executing when we migrated
44-- | Continue execution of the closure that we were executing when we migrated
45−-- to a new thread. Run the stack of pending functions in fstack. The types
45+-- to a new thread.
46−-- don't match. We just coerce the types here, we know that they actually match.
48−continue :: Monad m => Context -> StateT Context m (Maybe a)
47+resume :: Monad m => Context -> StateT Context m (Maybe a)
49−continue = runAsyncT . continueContext
48+resume = runAsyncT . resumeContext
51------------------------------------------------------------------------------
50------------------------------------------------------------------------------
52-- Thread Management (creation, reaping and killing)
51-- Thread Management (creation, reaping and killing)
@@ -211,7 +210,7 @@ genAsyncEvents parentc rec = forkMaybe parentc loop
211 -- pass on the io result and then run the continuation
210 -- pass on the io result and then run the continuation
212 runContWith dat cont = do
211 runContWith dat cont = do
213 let cont' = cont { event = Just $ unsafeCoerce dat }
212 let cont' = cont { event = Just $ unsafeCoerce dat }
214− _ <- runStateT (continue cont') cont'
213+ _ <- runStateT (resume cont') cont'
215 return ()
214 return ()
217-- | Run an IO action one or more times to generate a stream of tasks. The IO
216-- | Run an IO action one or more times to generate a stream of tasks. The IO
@@ -226,6 +225,7 @@ genAsyncEvents parentc rec = forkMaybe parentc loop
226parallel :: (Monad m, MonadIO m, MonadBaseControl IO m)
225parallel :: (Monad m, MonadIO m, MonadBaseControl IO m)
227 => IO (StreamData a) -> AsyncT m (StreamData a)
226 => IO (StreamData a) -> AsyncT m (StreamData a)
228parallel ioaction = AsyncT $ do
227parallel ioaction = AsyncT $ do
228+ -- receive the events via a channel instead
229 cont <- get
229 cont <- get
230 case event cont of
230 case event cont of
231 -- we have already exceuted the ioaction and now we are continuing in a new
231 -- we have already exceuted the ioaction and now we are continuing in a new
@@ -238,7 +238,7 @@ parallel ioaction = AsyncT $ do
238 Nothing -> do
238 Nothing -> do
239 lift $ genAsyncEvents cont ioaction
239 lift $ genAsyncEvents cont ioaction
240 loc <- getLocation
240 loc <- getLocation
241− when (loc /= RemoteNode) $ setLocation ForkedThread
241+ when (loc /= RemoteNode) $ setLocation WaitingParent
242 return Nothing
242 return Nothing
244-- | An task stream generator that produces an infinite stream of tasks by
244-- | An task stream generator that produces an infinite stream of tasks by
@@ -269,7 +269,7 @@ sync :: MonadIO m => AsyncT m a -> AsyncT m a
269sync x = AsyncT $ do
269sync x = AsyncT $ do
270 setLocation RemoteNode
270 setLocation RemoteNode
271 r <- runAsyncT x
271 r <- runAsyncT x
272− setLocation Local
272+ setLocation Worker
275-- | An task stream generator that produces an infinite stream of tasks by
275-- | An task stream generator that produces an infinite stream of tasks by
@@ -311,10 +311,10 @@ react setHandler iob = AsyncT $ do
311 case event cont of
311 case event cont of
312 Nothing -> do
312 Nothing -> do
313 lift $ setHandler $ \dat ->do
313 lift $ setHandler $ \dat ->do
314− runStateT (continue cont) cont{event= Just $ unsafeCoerce dat}
314+ runStateT (resume cont) cont{event= Just $ unsafeCoerce dat}
315 liftIO iob
315 liftIO iob
316 loc <- getLocation
316 loc <- getLocation
317− when (loc /= RemoteNode) $ setLocation ForkedThread
317+ when (loc /= RemoteNode) $ setLocation WaitingParent
318 return Nothing
318 return Nothing
320 j@(Just _) -> do
320 j@(Just _) -> do