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

Commitc0037fd

Browse files
thinkbeforecodinglatkin
authored andcommitted
Non generic Async.AwaitTask
commit b927d8cf5feeb8bc98881f4c3ebc22d67e8962adAuthor: latkin <latkin@microsoft.com>Date: Mon Oct 20 17:48:37 2014 -0700 Fix unit tests to handle lack of IDisposable for Task on some portable profilescommit d01c3dc8d2a52122d0a7d38b868a665a311ed7a2Author: latkin <latkin@microsoft.com>Date: Mon Oct 20 14:18:16 2014 -0700 Updating surface area testscommit ca27d14cc3b0cc04210646a04b184939c16479b8Merge:ef4388f d4583fbAuthor: latkin <latkin@microsoft.com>Date: Mon Oct 20 14:11:56 2014 -0700 Merge branch 'fsharp4' ofhttps://git01.codeplex.com/forks/thinkb4coding/visualfsharp into PRcommit d4583fb1ba3d40e589313c52f18a073519c34992Author: Jérémie Chassaing <jeremie.chassaing@thinkbeforecoding.com>Date: Sun Jul 6 17:40:18 2014 +0200 Add a check that the task is actually called with non generic Async.AwaitTaskcommit 8e7c4cf12466894998f837490972f088aa7ac5eaMerge: b111a5af3cd398Author: Jérémie Chassaing <jeremie.chassaing@thinkbeforecoding.com>Date: Thu Jun 26 10:36:16 2014 +0200 Merge branch 'fsharp4' ofhttps://git01.codeplex.com/visualfsharp into fsharp4commit b111a5a24f9c3821446341abd8a1ece72bf1821bAuthor: Jérémie Chassaing <jeremie.chassaing@thinkbeforecoding.com>Date: Wed Jun 25 13:02:23 2014 +0200 Non generic Async.AwaitTask
1 parent6221ab5 commitc0037fd

File tree

5 files changed

+64
-0
lines changed

5 files changed

+64
-0
lines changed

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,4 +269,58 @@ type AsyncType() =
269269
Async.Start a
270270
cts.Cancel()
271271
ewh.WaitOne(10000)|> ignore
272+
273+
[<Test>]
274+
memberthis.NonGenericTaskAsyncValue()=
275+
lethasBeenCalled= reffalse
276+
#if FSHARP_CORE_NETCORE_PORTABLE
277+
lett=
278+
#else
279+
use t=
280+
#endif
281+
Task.Factory.StartNew(Action(fun()-> hasBeenCalled:=true))
282+
leta=async{
283+
do! Async.AwaitTask(t)
284+
returntrue
285+
}
286+
letresult=Async.RunSynchronously(a,1000)
287+
(!hasBeenCalled&& result)|> Assert.IsTrue
288+
289+
[<Test>]
290+
memberthis.NonGenericTaskAsyncValueException()=
291+
#if FSHARP_CORE_NETCORE_PORTABLE
292+
lett=
293+
#else
294+
use t=
295+
#endif
296+
Task.Factory.StartNew(Action(fun()-> raise<| Exception()))
297+
leta=async{
298+
try
299+
let!v= Async.AwaitTask(t)
300+
returnfalse
301+
with e->returntrue
302+
}
303+
Async.RunSynchronously(a,1000)|> Assert.IsTrue
304+
305+
[<Test>]
306+
memberthis.NonGenericTaskAsyncValueCancellation()=
307+
use ewh=new ManualResetEvent(false)
308+
letcts=new CancellationTokenSource()
309+
lettoken= cts.Token
310+
#if FSHARP_CORE_NETCORE_PORTABLE
311+
lett=
312+
#else
313+
use t=
314+
#endif
315+
Task.Factory.StartNew(Action(fun()->whilenot token.IsCancellationRequesteddo()), token)
316+
letcancelled= reftrue
317+
leta=async{
318+
use! _holder= Async.OnCancel(fun _-> ewh.Set()|> ignore)
319+
let!v= Async.AwaitTask(t)
320+
return v
321+
}
322+
Async.Start a
323+
cts.Cancel()
324+
ewh.WaitOne(10000)|> ignore
325+
272326
#endif

‎src/fsharp/FSharp.Core.Unittests/SurfaceArea.4.0.fs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ Microsoft.FSharp.Control.FSharpAsync: Boolean Equals(System.Object)
531531
Microsoft.FSharp.Control.FSharpAsync: Int32 GetHashCode()
532532
Microsoft.FSharp.Control.FSharpAsync: Microsoft.FSharp.Control.FSharpAsync`1[Microsoft.FSharp.Control.FSharpAsync`1[T]] StartChild[T](Microsoft.FSharp.Control.FSharpAsync`1[T], Microsoft.FSharp.Core.FSharpOption`1[System.Int32])
533533
Microsoft.FSharp.Control.FSharpAsync: Microsoft.FSharp.Control.FSharpAsync`1[Microsoft.FSharp.Core.FSharpChoice`2[T,System.Exception]] Catch[T](Microsoft.FSharp.Control.FSharpAsync`1[T])
534+
Microsoft.FSharp.Control.FSharpAsync: Microsoft.FSharp.Control.FSharpAsync`1[Microsoft.FSharp.Core.Unit] AwaitTask(System.Threading.Tasks.Task)
534535
Microsoft.FSharp.Control.FSharpAsync: Microsoft.FSharp.Control.FSharpAsync`1[Microsoft.FSharp.Core.Unit] Ignore[T](Microsoft.FSharp.Control.FSharpAsync`1[T])
535536
Microsoft.FSharp.Control.FSharpAsync: Microsoft.FSharp.Control.FSharpAsync`1[Microsoft.FSharp.Core.Unit] Sleep(Int32)
536537
Microsoft.FSharp.Control.FSharpAsync: Microsoft.FSharp.Control.FSharpAsync`1[Microsoft.FSharp.Core.Unit] SwitchToContext(System.Threading.SynchronizationContext)

‎src/fsharp/FSharp.Core.Unittests/SurfaceArea.Portable.fs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,7 @@ Microsoft.FSharp.Control.FSharpAsync: Boolean Equals(System.Object)
525525
Microsoft.FSharp.Control.FSharpAsync: Int32 GetHashCode()
526526
Microsoft.FSharp.Control.FSharpAsync: Microsoft.FSharp.Control.FSharpAsync`1[Microsoft.FSharp.Control.FSharpAsync`1[T]] StartChild[T](Microsoft.FSharp.Control.FSharpAsync`1[T], Microsoft.FSharp.Core.FSharpOption`1[System.Int32])
527527
Microsoft.FSharp.Control.FSharpAsync: Microsoft.FSharp.Control.FSharpAsync`1[Microsoft.FSharp.Core.FSharpChoice`2[T,System.Exception]] Catch[T](Microsoft.FSharp.Control.FSharpAsync`1[T])
528+
Microsoft.FSharp.Control.FSharpAsync: Microsoft.FSharp.Control.FSharpAsync`1[Microsoft.FSharp.Core.Unit] AwaitTask(System.Threading.Tasks.Task)
528529
Microsoft.FSharp.Control.FSharpAsync: Microsoft.FSharp.Control.FSharpAsync`1[Microsoft.FSharp.Core.Unit] Ignore[T](Microsoft.FSharp.Control.FSharpAsync`1[T])
529530
Microsoft.FSharp.Control.FSharpAsync: Microsoft.FSharp.Control.FSharpAsync`1[Microsoft.FSharp.Core.Unit] Sleep(Int32)
530531
Microsoft.FSharp.Control.FSharpAsync: Microsoft.FSharp.Control.FSharpAsync`1[Microsoft.FSharp.Core.Unit] SwitchToContext(System.Threading.SynchronizationContext)

‎src/fsharp/FSharp.Core/control.fs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1961,6 +1961,11 @@ namespace Microsoft.FSharp.Control
19611961
protectedPrimitiveWithResync(fun args->
19621962
TaskHelpers.continueWith(task, args)
19631963
)
1964+
1965+
static memberAwaitTask(task:Task):Async<unit>=
1966+
protectedPrimitiveWithResync(fun args->
1967+
TaskHelpers.continueWithUnit(task, args)
1968+
)
19641969
#endif
19651970

19661971
moduleCommonExtensions=

‎src/fsharp/FSharp.Core/control.fsi‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,9 @@ namespace Microsoft.FSharp.Control
341341
/// Return an asynchronous computation that will wait for the given task to complete and return
342342
/// its result.
343343
static member AwaitTask: task: Task<'T>-> Async<'T>
344+
/// Return an asynchronous computation that will wait for the given task to complete and return
345+
/// its result.
346+
static member AwaitTask: task: Task-> Async<unit>
344347
#endif
345348

346349
///<summary>Creates an asynchronous computation that will sleep for the given time. This is scheduled

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp