.
[clean-tests.git] / cloudiTasks / cloudiTasks.icl
1 module cloudiTasks
2
3 import Data.Func, Data.Functor, Data.Tuple
4 import StdEnv
5 import iTasks
6
7 Start w = doTasks master w
8
9 master :: Task ()
10 master
11 = get applicationOptions
12 >>- \eo->traceValue ("Master started on port " +++ toString eo.serverPort)
13 // >-| set 42 (remoteShare (sharedStore "bork" 42) {domain="localhost",port=9099})
14 // >-| asyncTask (ExistingNode "localhost" 9099) (blockWait 5)
15 // >-| asyncTask "localhost" 9090 (blockWait 5)
16 // >-| asyncTask (PrivateNode 9099) (traceValue 5 >-| traceValue 42)
17 >-| asyncTask "localhost" 9099 (updateInformation [] 5)
18 // >-| sleepSortPar [5,1,3,8]
19 >&^ viewSharedInformation []
20 @! ()
21
22 blockWait :: Int -> Task Int
23 blockWait i = accWorld (sleep i)
24 where
25 sleep :: !Int !*e -> (!Int, !*e)
26 sleep _ _ = code {
27 ccall sleep "I:I:A"
28 }
29
30 sleepSortPar :: [Int] -> Task [Int]
31 sleepSortPar numbers = parallel
32 [ (Embedded, \stl->
33 asyncTaskSpawn port (blockWait num)
34 >-| appendTask Embedded (\_->return num) stl
35 @? const NoValue)
36 \\ num <- numbers
37 & port <- [9092..9099]
38 ] [] @? \tv->case tv of
39 NoValue = NoValue
40 (Value ts _)
41 # r = [v\\(_, Value v True)<-ts]
42 = Value r (length r == length numbers)