Verified Commit 8291ce34 authored by Camil Staps's avatar Camil Staps 🚀

Simplify withShared

parent 139374cc
......@@ -30,23 +30,25 @@ where
evalinit event evalOpts=:{TaskEvalOpts|taskId} iworld
# (taskIda, iworld) = getNextTaskId iworld
# (e, iworld) = write (?Just initial) (sdsFocus taskId localShare) EmptyContext iworld
# localSds = sdsFocus taskId localShare
# (e, iworld) = write (?Just initial) localSds EmptyContext iworld
| isError e
= (ExceptionResult (fromError e),iworld)
= eval
taskIda
(stask $ mapWrite (\w _ -> ?Just $ ?Just w) ?None $ sdsFocus taskId localShare)
localSds
(stask $ mapWrite (\w _ -> ?Just $ ?Just w) ?None localSds)
event
evalOpts
iworld
//Running
eval innerTaskId (Task inner) ServerInterruptedEvent opts iworld
eval :: !TaskId !(SDSLens () b (?b)) !(Task a) !Event !TaskEvalOpts !*IWorld -> (!TaskResult a, !*IWorld) | TC b
eval innerTaskId localSds (Task inner) ServerInterruptedEvent opts iworld
= inner ServerInterruptedEvent {TaskEvalOpts|opts&taskId=innerTaskId} iworld
eval innerTaskId (Task inner) DestroyEvent opts iworld
eval innerTaskId localSds (Task inner) DestroyEvent opts iworld
// free memory of share
# (e, iworld) =
write (noneWithSameTypeAs initial) (sdsFocus opts.TaskEvalOpts.taskId localShare) EmptyContext iworld
# (e, iworld) = write ?None localSds EmptyContext iworld
| isError e
= (ExceptionResult (fromError e),iworld)
= case inner DestroyEvent {TaskEvalOpts|opts&taskId=innerTaskId} iworld of
......@@ -54,16 +56,13 @@ where
= (ExceptionResult (exception "Failed to destroy withShared child"), iworld)
e = e
eval innerTaskId (Task inner) event evalOpts=:{TaskEvalOpts|taskId,lastEval} iworld
eval innerTaskId localSds (Task inner) event evalOpts=:{TaskEvalOpts|taskId,lastEval} iworld
= case inner event {TaskEvalOpts|evalOpts&taskId=innerTaskId} iworld of
(ValueResult val info rep newinner, iworld)
# info = {TaskEvalInfo|info & lastEvent = max lastEval info.TaskEvalInfo.lastEvent}
= (ValueResult val info rep (Task (eval innerTaskId newinner)), iworld)
# info & TaskEvalInfo.lastEvent = max lastEval info.TaskEvalInfo.lastEvent
= (ValueResult val info rep (Task (eval innerTaskId localSds newinner)), iworld)
e = e
noneWithSameTypeAs :: a -> ?a
noneWithSameTypeAs _ = ?None
withTaskId :: (Task a) -> Task (a, TaskId)
withTaskId (Task task) = Task eval
where
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment