@@ -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, .. }
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------------------------------------------------------------------------------
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
180 return mres
183 return mres
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.
189+-- This function composes the stored context to recover the computation.
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
191 unsafeCoerce m >>= composefStack (unsafeCoerce fs)
195 unsafeCoerce m >>= composefStack (unsafeCoerce fs)