Verified Commit 139374cc authored by Camil Staps's avatar Camil Staps 🚀

Add clearEventsOf to be able to remove outdated TaskIds from a RefreshEvent...

Add clearEventsOf to be able to remove outdated TaskIds from a RefreshEvent during the evaluation of a task (fixes a memory leak in which the RefreshEvent would grow)
parent 92ae22a1
......@@ -66,6 +66,9 @@ dequeueEvent :: !*IWorld -> (!MaybeError TaskException (?QueuedEvent),!*IWorld)
*/
clearEvents :: !InstanceNo !*IWorld -> *IWorld
//* Remove all events for a given task.
clearEventsFor :: !TaskId !*IWorld -> *IWorld
/**
* Queue different types of output at once
*/
......
......@@ -102,6 +102,30 @@ where
[|f \\ f=:{QueuedEvent | instanceNo=i} <|- fs | i <> instanceNo]
[|b \\ b=:{QueuedEvent | instanceNo=i} <|- bs | i <> instanceNo]
clearEventsFor :: !TaskId !*IWorld -> *IWorld
clearEventsFor taskId=:(TaskId ino _) iworld = snd (modify clear taskEvents EmptyContext iworld)
where
clear :: !TaskInput -> TaskInput
clear (Queue front rear) = Queue (upd front) (upd rear)
where
upd [|]
= [|]
upd [|qe=:{instanceNo,event}:rest] | instanceNo <> ino
= [|qe:upd rest]
upd [|qe=:{event=RefreshEvent ids}:rest]
= case 'DS'.delete taskId ids of
'DS'.Tip = upd rest
ids = [|{qe & event=RefreshEvent ids}:upd rest]
upd [|qe=:{event=EditEvent id _ _}:rest]
| id == taskId
= upd rest
= [|qe:upd rest]
upd [|qe=:{event=ActionEvent id _}:rest]
| id == taskId
= upd rest
= [|qe:upd rest]
upd [|qe:rest] = [|qe:upd rest]
queueOutput :: !InstanceNo ![TaskOutputMessage] !*IWorld -> *IWorld
queueOutput instanceNo messages iworld
# (_,iworld) = 'SDS'.modify (enqueueAll messages) (sdsFocus instanceNo taskInstanceOutput) 'SDS'.EmptyContext iworld
......
......@@ -744,7 +744,7 @@ where
= eval (ASAttached (status =: (Right True))) build (?Just newKey) event evalOpts iworld
eval _ _ _ DestroyEvent evalOpts=:{TaskEvalOpts|taskId} iworld
# iworld = clearTaskSDSRegistrations ('DS'.singleton taskId) iworld
# iworld = clearTaskSDSRegistrations ('DS'.singleton taskId) (clearEventsFor taskId iworld)
# (_,iworld) = modify release (sdsFocus (instanceNo,False,True) taskInstance) EmptyContext iworld
= (DestroyedResult, iworld)
where
......
......@@ -6,6 +6,7 @@ import iTasks.WF.Definition
import iTasks.UI.Definition
import iTasks.SDS.Definition
import iTasks.Internal.Task
import iTasks.Internal.TaskIO
import iTasks.Internal.TaskState
import iTasks.Internal.TaskEval
import iTasks.Internal.IWorld
......@@ -107,7 +108,7 @@ evalInteract ::
evalInteract _ _ _ _ _ _ _ _ ServerInterruptedEvent _ iworld
= (DestroyedResult, iworld)
evalInteract _ _ _ _ _ _ _ _ DestroyEvent {TaskEvalOpts|taskId} iworld
= (DestroyedResult, 'SDS'.clearTaskSDSRegistrations ('DS'.singleton taskId) iworld)
= (DestroyedResult, 'SDS'.clearTaskSDSRegistrations ('DS'.singleton taskId) (clearEventsFor taskId iworld))
evalInteract _ mbr ?None _ sds editor modefun writefun event=:(EditEvent eTaskId name edit) evalOpts=:{taskId,lastEval} iworld
= (ExceptionResult (exception "corrupt editor state"), iworld)
evalInteract prevChange mbr (?Just st) editorId sds editor modefun writefun event=:(EditEvent eTaskId name edit) evalOpts=:{taskId,lastEval} iworld | eTaskId == taskId
......
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