module cloudiTasks
-import Data.Func
+import Data.Func, Data.Functor, Data.Tuple
import StdEnv
import iTasks
import iTasks.Extensions.DateTime
-import iTasks.Extensions.Distributed
-Start w = flip doTasksWithOptions w \args eo
- # (eo, s) = case args of
- [argv0,"--slave",p] = ({eo & sdsPort=toInt p}, onStartup o slave)
- //_ = (eo, onRequest "/" o master)
- _ = (eo, onStartup o master)
- = Ok (s args, {eo & distributed=True})
+Start w = doTasks master w
-slave :: [String] -> Task ()
-slave args
- = get applicationOptions
- >>- \eo->traceValue ("Slave started on port " +++ toString eo.sdsPort)
- >-| asyncTaskListener
-
-master :: [String] -> Task ()
-master args
+master :: Task ()
+master
= get applicationOptions
>>- \eo->traceValue ("Master started on port " +++ toString eo.serverPort)
-// >-| asyncTask (PrivateNode 9099 ["--slave", "9099"]) (blockWait 5)
-// >-| asyncTask (PrivateNode 9099 ["--slave", "9099"]) (traceValue 5 >-| traceValue 42)
// >-| asyncTask (ExistingNode "localhost" 9099) (blockWait 5)
- >-| sleepSortPar [1,2,3,4]
-// >&> viewSharedInformation []
- >>- traceValue
+ >-| asyncTask (PrivateNode 9099) (blockWait 5)
+// >-| asyncTask (PrivateNode 9099) (traceValue 5 >-| traceValue 42)
+// >-| asyncTask (PrivateNode 9099) (updateInformation [] 42)
+// >-| sleepSortPar [5,1,3,8]
+ >&^ viewSharedInformation []
@! ()
blockWait :: Int -> Task Int
ccall sleep "I:I:A"
}
-sleepSort :: [Int] -> Task [Int]
-sleepSort numbers = parallel
- [ (Embedded, \_->waitForTimer False num >-| return num)
- \\ num <- numbers
- ] [] @? tresult (length numbers)
-
sleepSortPar :: [Int] -> Task [Int]
sleepSortPar numbers = parallel
- [ (Embedded, \_->asyncTask
- (PrivateNode port ["--slave", toString port])
- $ blockWait num >-| return num)
+ [ (Embedded, \stl->
+ asyncTask (PrivateNode port) (blockWait num)
+ >-| appendTask Embedded (\_->return num) stl
+ @? const NoValue)
\\ num <- numbers
& port <- [9091..9099]
- ] [] @? tresult (length numbers)
-
-tresult l NoValue = NoValue
-tresult l (Value ts _)
- = let r = [v\\(_, Value v True)<-ts] in Value r (length r == l)
+ ] [] @? \tv->case tv of
+ NoValue = NoValue
+ (Value ts _)
+ # r = [v\\(_, Value v True)<-ts]
+ = Value r (length r == length numbers)