Created
February 15, 2013 15:30
-
-
Save mavnn/4961072 to your computer and use it in GitHub Desktop.
Don't do this
This file contains hidden or 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 inline doParallelWithThrottle limit f items = | |
use sem = new System.Threading.Semaphore(limit, limit) | |
items | |
|> Seq.map (fun element -> async { | |
sem.WaitOne() |> ignore | |
let result = Async.RunSynchronously <| async { return f element } | |
sem.Release() |> ignore | |
return result | |
}) | |
|> Async.Parallel | |
|> Async.RunSynchronously |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment