on master help sign in
rename resumeContext to composeContext
3103c1cHarendra Kumar
src/Strands/Context.hs+12−8
@@ -8,7 +8,7 @@ module Strands.Context
8 , initContext
8 , initContext
9 , saveContext
9 , saveContext
10 , restoreContext
10 , restoreContext
11− , resumeContext
11+ , composeContext
12 , setContextMailBox
12 , setContextMailBox
13 , takeContextMailBox
13 , takeContextMailBox
14 , getCtxResultDest
14 , getCtxResultDest
@@ -151,7 +151,10 @@ setLocation :: Monad m => Location -> StateT Context m ()
151setLocation loc = Lazy.modify $ \Context { .. } -> Context { location = loc, .. }
151setLocation loc = Lazy.modify $ \Context { .. } -> Context { location = loc, .. }
152
152
153------------------------------------------------------------------------------
153------------------------------------------------------------------------------
154−-- Saving and restoring the context of a computation
154+-- Saving and restoring the context of a computation. We perform the monadic
155+-- computation one step at a time storing the context of where we are in the
156+-- computation. At any point the remaining computation can be fully recovered
157+-- from this context.
155------------------------------------------------------------------------------
158------------------------------------------------------------------------------
156
159
157-- Save the 'm' and 'f', in case we migrate to a new thread before the current
160-- Save the 'm' and 'f', in case we migrate to a new thread before the current
@@ -179,13 +182,14 @@ restoreContext x = do
179
182
180 return mres
183 return mres
181
184
182−-- | Resume execution of the computation from a given context. We can retrieve
183−-- a context at any point and resume that context at some later point, upon
185+-- | We can retrieve a context at any point and resume that context at some
184−-- resumption we start executing again from the same point where the context
186+-- later point, upon resumption we start executing again from the same point
185−-- was retrieved.
187+-- where the context was retrieved from.
186--
188--
189+-- This function composes the stored context to recover the computation.
190+--
187−resumeContext :: (MonadIO m, MonadPlus m) => Context -> m a
191+composeContext :: (MonadIO m, MonadPlus m) => Context -> m a
188−resumeContext Context { currentm = m
192+composeContext Context { currentm = m
189 , fstack = fs
193 , fstack = fs
190 } =
194 } =
191 unsafeCoerce m >>= composefStack (unsafeCoerce fs)
195 unsafeCoerce m >>= composefStack (unsafeCoerce fs)
src/Strands/Threads.hs+1−2
@@ -73,8 +73,7 @@ import Strands.Context
73
73
74runContext :: MonadIO m => Context -> StateT Context m ()
74runContext :: MonadIO m => Context -> StateT Context m ()
75runContext ctx = do
75runContext ctx = do
76− -- XXX rename to buildContext or buildState?
77− let s = runAsyncT (resumeContext ctx)
76+ let s = runAsyncT (composeContext ctx)
78 _ <- lift $ runStateT s ctx
77 _ <- lift $ runStateT s ctx
79 return ()
78 return ()
80
79