.'
[clean-tests.git] / cloudiTasks / cloudiTasks.icl
index 081848e..1cd0d36 100644 (file)
@@ -1,14 +1,16 @@
 module cloudiTasks
 
+import Data.Func
 import StdEnv
 import iTasks
-import Data.Func
+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, onRequest "/" o master)
+               _ = (eo, onStartup o master)
        = Ok (s args, {eo & distributed=True})
 
 slave :: [String] -> Task ()
@@ -21,9 +23,12 @@ master :: [String] -> Task ()
 master args
        = get applicationOptions
        >>- \eo->traceValue ("Master started on port " +++ toString eo.serverPort)
-       >-| asyncTask (PrivateNode 9099 ["--slave", "9099"]) (blockWait 5)
+//     >-| asyncTask (PrivateNode 9099 ["--slave", "9099"]) (blockWait 5)
+//     >-| asyncTask (PrivateNode 9099 ["--slave", "9099"]) (traceValue 5 >-| traceValue 42)
 //     >-| asyncTask (ExistingNode "localhost" 9099) (blockWait 5)
-       >>! \s->viewInformation [] s
+       >-| sleepSortPar [1,2,3,4]
+//     >&> viewSharedInformation []
+       >>- traceValue
        @! ()
 
 blockWait :: Int -> Task Int
@@ -33,3 +38,22 @@ where
        sleep _ _ = code {
                        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)
+       \\ 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)