Commit 8aedd474 authored by Mart Lubbers's avatar Mart Lubbers

rewrite sequence in terms of foreverStIf to not leak memory

parent 4842d549
Pipeline #13111 failed with stage
in 2 minutes and 11 seconds
......@@ -147,13 +147,12 @@ justdo :: !(Task (Maybe a)) -> Task a | iTask a
/**
* Execute the list of tasks one after another.
*
* @param Label: A label for tracing
* @param Tasks: The list of tasks to be executed sequentially
* @return The combined task
*
* @gin-icon sequence
*/
sequence :: !String ![Task a] -> Task [a] | iTask a
sequence :: ![Task a] -> Task [a] | iTask a
/**
* Repeats a task until a given predicate holds. The predicate is tested as soon as the
......
......@@ -90,11 +90,17 @@ justdo task
Just x = return x
Nothing = throw ("The task returned nothing.")
sequence :: !String ![Task a] -> Task [a] | iTask a
sequence _ tasks = seqTasks tasks
where
seqTasks [] = return []
seqTasks [t:ts] = t >>- \a -> seqTasks ts >>- \as -> return [a:as]
sequence :: ![Task a] -> Task [a] | iTask a
sequence tasks = foreverStIf
//Continue while there are tasks left
(not o isEmpty o snd)
//Initial state, empty accumulator, all tasks
([], tasks)
//Run the first task and add it to the accumulator
(\(acc, [todo:todos])->todo >>- \t->treturn ([t:acc], todos))
//When done, just return the accumulator
@ fst
foreverStIf :: (a -> Bool) a !(a -> Task a) -> Task a | iTask a
foreverStIf pred st t = parallel [(Embedded, par st Nothing)] []
......
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