New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from Aug 25, 2016

Conversation

Projects
None yet
2 participants
@Thorium
Member

Thorium commented Aug 24, 2016

No comments.

Thorium added some commits Aug 24, 2016

Smaller closure signature capture.
Editted directly from GitHub online.
@Thorium

This comment has been minimized.

Show comment
Hide comment
@Thorium

Thorium Aug 25, 2016

Member

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
Member

Thorium commented Aug 25, 2016

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

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@forki

This comment has been minimized.

Show comment
Hide comment
@forki

forki Aug 25, 2016

Member

thanks!

Member

forki commented Aug 25, 2016

thanks!

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