Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Async cache fix in multi-thread-environment for GitHub downloads #1880
Hehe... first some solution and then more optimized. The last one looks quite nice and the unit test proofs it's working while the normal F# Async won't serialize "correctly".
let internal memoizeAsync f = let cache = System.Collections.Concurrent.ConcurrentDictionary<'a, System.Threading.Tasks.Task<'b>>() fun x -> // task.Result serialization to sync after done. cache.GetOrAdd(x, fun x -> f(x) |> Async.StartAsTask) |> Async.AwaitTask