Commit dd326468 authored by Rinus Plasmeijer's avatar Rinus Plasmeijer
Browse files

lazy tasks added

parent c7fdfea5
......@@ -8,16 +8,11 @@ import StdHtml
:: Task a :== St *TSt a // an interactive task
:: IDataFun a :== St *HSt (Form a) // an iData Form
LTask :: String (Task a) *TSt -> (Task Bool,Maybe a,*TSt) | gForm{|*|}, gUpd{|*|}, gPrint{|*|}, gParse{|*|}, TC a
derive gForm Maybe
derive gUpd Maybe
derive gPrint Maybe
derive gParse Maybe
/*
startTask :: lift iData to iTask domain
mkTask :: promote TSt state function to an interactive Task, i.e. task will only be called when it is its turn
mkLTask :: split indicated task in a lazy task and
a task which can be used to activate that lazy task aftrewhich it waits for its completion and result
STask :: a Sequential iTask
STask_button :: do corresponding iTask when button pressed
......@@ -44,6 +39,8 @@ appIData :: lift iData editors to iTask domain
startTask :: (Task a) *HSt -> ([BodyTag],HSt) | gForm{|*|}, gUpd{|*|}, gPrint{|*|}, gParse{|*|}, TC a
mkTask :: (*TSt -> *(a,*TSt)) -> (Task a) | gForm{|*|}, gUpd{|*|}, gPrint{|*|}, gParse{|*|}, TC a
mkLTask :: String (Task a) *TSt -> (Task a,Task a,*TSt)
| gForm{|*|}, gUpd{|*|}, gPrint{|*|}, gParse{|*|}, TC a
STask :: String a -> (Task a) | gForm{|*|}, gUpd{|*|}, gPrint{|*|}, gParse{|*|}, TC a
STask_button :: String (Task a) -> (Task a) | gForm{|*|}, gUpd{|*|}, gPrint{|*|}, gParse{|*|}, TC a
......@@ -60,6 +57,7 @@ PCTasks :: [(String,Task a)] -> (Task a) | gForm{|*|}, gUpd{|*|}, gPrint{|*|
PTask2 :: (Task a,Task b) -> (Task (a,b)) | gForm{|*|}, gUpd{|*|}, gPrint{|*|}, gParse{|*|}, TC a & gForm{|*|}, gUpd{|*|}, gPrint{|*|}, gParse{|*|}, TC b
PTasks :: [(String,Task a)] -> (Task [a]) | gForm{|*|}, gUpd{|*|}, gPrint{|*|}, gParse{|*|}, TC a
returnTask :: a -> (Task a) | gForm{|*|}, gUpd{|*|}, gPrint{|*|}, gParse{|*|}, TC a
returnVF :: a [BodyTag] -> (Task a) | gForm{|*|}, gUpd{|*|}, gPrint{|*|}, gParse{|*|}, TC a
returnV :: a -> (Task a) | gForm{|*|}, gUpd{|*|}, gPrint{|*|}, gParse{|*|}, TC a
......
......@@ -13,34 +13,35 @@ derive gPrint Niks
// lazy task ???
LTask :: String (Task a) *TSt -> (Task Bool,Maybe a,*TSt) | gForm{|*|}, gUpd{|*|}, gPrint{|*|}, gParse{|*|}, TC a
LTask s task tst=:((j,myturn,html),hst)
# (bt,(mba,tst)) = LazyTask` s task (incTask tst)
= (bt,mba,tst)
mkLTask :: String (Task a) *TSt -> (Task a,Task a,*TSt) | gForm{|*|}, gUpd{|*|}, gPrint{|*|}, gParse{|*|}, TC a
mkLTask s task tst = LazyTask` s task (incTask tst)
where
LazyTask` s task tst=:((_,myturn,html),hst) = (BT,LT s task tst)
LazyTask` s task tst=:((j,myturn,html),hst) = (bossTask, workerTask s task,tst)
where
LT s task tst = mkTask (LT` s task) tst
workerTask s task tst = mkTask (workerTask` s task) tst
where
LT` s task tst=:((i,myturn,html),hst)
# (todo,hst) = mkEditForm (Init,nFormId editId False) hst
| todo.value
# (a,((i,adone,ahtml),hst)) = task ((i,True,[]),hst)
= (Just a,((i,True,html <|.|> if adone [] [Txt ("lazy task \"" +++ s +++ "\" activated"),Br] <|.|> ahtml),hst))
= (Nothing,((i,True,html),hst))
workerTask` s task tst=:((i,myturn,html),hst)
# (todo,hst) = checkBossSignal id hst // check whether lazy task evaluation has to be done
| todo.value // yes
# (a,((_,adone,ahtml),hst)) = task ((j++[0],True,[]),hst) // do task
# (_,hst) = lazyTaskStore (\_ -> (adone,a)) hst // store task and status
= (a,((i,myturn,html <|.|> if adone [] [Txt ("lazy task \"" +++ s +++ "\" activated:"),Br] <|.|> ahtml),hst))
= (createDefault,((i,myturn,html),hst)) // no
BT tst = mkTask (BT`) tst
bossTask tst = mkTask (bossTask`) tst
where
BT` tst=:((i,myturn,html),hst)
# (todo,hst) = mkEditForm (Init,nFormId editId False) hst
= (todo.value,incTask ((i,myturn,html<|.|>todo.form ),hst))
bossTask` tst=:((i,myturn,html),hst)
# buttonId = "getlt" <+++ mkTaskNr i
# (finbut,hst) = simpleButton buttonId s (\_ -> True) hst // button press will trigger related lazy task
# (todo,hst) = checkBossSignal finbut.value hst // set store True if button pressed
# (result,hst) = lazyTaskStore id hst // inspect status task
# (done,value) = result.value
| not done = (createDefault,((i,False,html<|.|>if todo.value [Txt ("Waiting for task \"" +++ s +++ "\"..")] finbut.form),hst))
= (value,((i,myturn,html <|.|> [Txt ("Result of lazy task \"" +++ s +++ "\" :")]),hst))
editId = "signal_xxx" <+++ mkTaskNr j
lazyTaskStore fun = mkStoreForm (Init,sFormId ("getLT" <+++ mkTaskNr j) (False,createDefault)) fun
checkBossSignal fun = mkStoreForm (Init,sFormId ("setLT" <+++ mkTaskNr j) (fun False)) fun
derive gForm Maybe
derive gUpd Maybe
derive gPrint Maybe
derive gParse Maybe
startTask :: (Task a) *HSt -> ([BodyTag],HSt) | gForm{|*|}, gUpd{|*|}, gPrint{|*|}, gParse{|*|}, TC a
startTask taska hst
......
Supports Markdown
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