Created
June 14, 2012 21:23
-
-
Save cocodrino/2933038 to your computer and use it in GitHub Desktop.
F# code 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let rec factorial(n : int) (mem : bigint) = | |
match n with | |
| 0 | 1 -> printfn "%A" mem | |
| _ -> factorial (n - 1) (mem * bigint(n)) | |
let BigFactorial(numero,mesaje)= | |
Async.FromContinuations(fun (cont,error,cancelation) -> | |
printfn "begin number: %s" mesaje | |
factorial numero 1I |>ignore | |
printfn "begin number: %s ." mesaje | |
cont()) | |
//this doesn't works in async way...I get the 30M result first and then run the 10M | |
Async.RunSynchronously(async{ | |
printfn "Start!!..." | |
do! BigFactorial(30000,"30M") | |
do! BigFactorial(10000, "10M") | |
printfn "End!!..." | |
}) | |
//this works nicely | |
let task1 = async{ | |
printfn "begin" | |
do! BigFactorial(30000,"30") | |
printfn "end..." | |
} | |
let task2 = async{ | |
printfn "begin" | |
do! BigFactorial(10000,"10") | |
printfn "end!!..." | |
} | |
Async.RunSynchronously(Async.Parallel[task1;task2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment