Last active
April 3, 2018 13:19
-
-
Save Szer/60c9c88bec822463bd4af86371f2663b to your computer and use it in GitHub Desktop.
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
open System | |
let random = Random(int DateTime.UtcNow.Ticks) | |
let asyncMockup s = async { | |
let sleepFor = int (random.NextDouble() * 3000.) | |
//let sleepFor = 2000 | |
do! Async.Sleep sleepFor | |
printfn "resulted %s" s | |
return sprintf "resulted %s" s | |
} | |
let inline (>>-) x f = async.Bind(x, f >> async.Return) | |
let requestMasterAsync limit urls = | |
let results = Array.zeroCreate (List.length urls) | |
let chunks = | |
urls | |
|> Seq.chunkBySize limit | |
|> Seq.indexed | |
async.For (chunks, fun (i, chunk) -> | |
chunk | |
|> Seq.map asyncMockup | |
|> Async.Parallel | |
>>- Seq.iteri (fun j r -> results.[i*limit+j]<-r)) | |
>>- fun _ -> results | |
let results = | |
List.init 20 string | |
|> requestMasterAsync 3 | |
|> Async.RunSynchronously |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment