Skip to content

Commit 44fd4ba

Browse files
committed
Unit test proofs that lazy is not needed, but Task serialization definitely is.
1 parent 2d4b05e commit 44fd4ba

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

‎src/Paket.Core/Utils.fs‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ let internal memoize (f: 'a -> 'b) : 'a -> 'b =
3131
let internal memoizeAsync f =
3232
let cache = System.Collections.Concurrent.ConcurrentDictionary<'a, System.Threading.Tasks.Task<'b>>()
3333
fun (x: 'a) -> // task.Result serialization to sync after done.
34-
cache.GetOrAdd(x, fun x -> // Lazy is needed for "if managed to start multiple before added"
35-
let threadfix = lazy( f(x) |> Async.StartAsTask )
36-
threadfix.Force()) |> Async.AwaitTask
34+
cache.GetOrAdd(x, fun x -> f(x) |> Async.StartAsTask) |> Async.AwaitTask
3735

3836
type Auth =
3937
| Credentials of Username : string * Password : string

‎tests/Paket.Tests/DependenciesFile/ParserSpecs.fs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,8 @@ let ``async cache should work``() =
13591359
do! memFunc "a" |> Async.Ignore
13601360
do! memFunc "a" |> Async.Ignore
13611361
do! memFunc "a" |> Async.Ignore
1362+
do! [|1 .. 30|] |> Seq.map(fun _ -> (memFunc "a"))
1363+
|> Async.Parallel |> Async.Ignore
13621364
for i = 1 to 30 do
13631365
Async.Start( memFunc "a" |> Async.Ignore )
13641366
Async.Start( memFunc "a" |> Async.Ignore )
@@ -1367,6 +1369,8 @@ let ``async cache should work``() =
13671369
do! memFunc "a" |> Async.Ignore
13681370
for i = 1 to 30 do
13691371
Async.Start( memFunc "a" |> Async.Ignore )
1372+
do! [|1 .. 30|] |> Seq.map(fun _ -> (memFunc "a"))
1373+
|> Async.Parallel |> Async.Ignore
13701374
} |> Async.RunSynchronously
13711375
x |> shouldEqual 1
13721376

0 commit comments

Comments
 (0)