Skip to content

Instantly share code, notes, and snippets.

@mavnn
Created February 15, 2013 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mavnn/4961072 to your computer and use it in GitHub Desktop.
Save mavnn/4961072 to your computer and use it in GitHub Desktop.
Don't do this
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