Skip to content

Async cache fix in multi-thread-environment for GitHub downloads - #1880

Merged
forki merged 5 commits into
fsprojects:masterfrom
Thorium:master
Aug 25, 2016
Merged

forki merged 5 commits into
fsprojects:masterfrom
Thorium:master

Conversation

@Thorium

@Thorium Thorium commented Aug 24, 2016

Copy link
Copy Markdown
Member

No comments.

@Thorium

Thorium commented Aug 25, 2016 •

Copy link
Copy Markdown
Member Author

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

@forki
forki merged commit 44fd4ba into fsprojects:master Aug 25, 2016
@forki

forki commented Aug 25, 2016

Copy link
Copy Markdown
Member

thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants