Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7af8b4a

Browse files
forkiKevinRansom
authored andcommitted
Port a test from Paket over to FSharp.Core tests (#3350)
1 parent000acd3 commit7af8b4a

File tree

1 file changed

+39
-1
lines changed
  • src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Control

1 file changed

+39
-1
lines changed

‎src/fsharp/FSharp.Core.Unittests/FSharp.Core/Microsoft.FSharp.Control/AsyncModule.fs‎

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ open NUnit.Framework
1313
openFsCheck
1414
#endif
1515

16+
moduleUtils=
17+
letinternalmemoizeAsync f=
18+
letcache= System.Collections.Concurrent.ConcurrentDictionary<'a, System.Threading.Tasks.Task<'b>>()
19+
fun(x: 'a)->// task.Result serialization to sync after done.
20+
cache.GetOrAdd(x,fun x-> f(x)|> Async.StartAsTask)|> Async.AwaitTask
21+
1622
type[<Struct>]Dummy(x: int)=
1723
memberthis.X= x
1824
interface IDisposablewith
@@ -602,4 +608,36 @@ type AsyncModule() =
602608
for i=1to3do test()
603609
Assert.AreEqual(0,!okCount)
604610
Assert.AreEqual(0,!errCount)
605-
#endif
611+
#endif
612+
613+
[<Test>]
614+
memberthis.``Async caching should work``()=
615+
letx= ref0
616+
letsomeSlowFunc _mykey=async{
617+
Console.WriteLine"Simulated downloading..."
618+
do! Async.Sleep400
619+
Console.WriteLine"Simulated downloading Done."
620+
x:=!x+ 1// Side effect!
621+
return""}
622+
623+
letmemFunc= Utils.memoizeAsync<| someSlowFunc
624+
625+
async{
626+
do! memFunc"a"|> Async.Ignore
627+
do! memFunc"a"|> Async.Ignore
628+
do! memFunc"a"|> Async.Ignore
629+
do![|1..30|]|> Seq.map(fun _->(memFunc"a"))
630+
|> Async.Parallel|> Async.Ignore
631+
for_i=1to30do
632+
Async.Start( memFunc"a"|> Async.Ignore)
633+
Async.Start( memFunc"a"|> Async.Ignore)
634+
do! Async.Sleep500
635+
do! memFunc"a"|> Async.Ignore
636+
do! memFunc"a"|> Async.Ignore
637+
for_i=1to30do
638+
Async.Start( memFunc"a"|> Async.Ignore)
639+
640+
do![|1..30|]|> Seq.map(fun _->(memFunc"a"))
641+
|> Async.Parallel|> Async.Ignore
642+
}|> Async.RunSynchronously
643+
Assert.AreEqual(1,!x)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp