1
0
Эх сурвалжийг харах

Adding explicit rendez-vous for scheduling.

Bart De Smet 8 жил өмнө
parent
commit
868d8bbb68

+ 24 - 0
AsyncRx.NET/System.Reactive.Async/System/Reactive/Concurrency/AsyncScheduler.cs

@@ -0,0 +1,24 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the Apache 2.0 License.
+// See the LICENSE file in the project root for more information. 
+
+using System.Runtime.CompilerServices;
+using System.Threading.Tasks;
+
+namespace System.Reactive.Concurrency
+{
+    public static class AsyncScheduler
+    {
+        // TODO: Implement proper RendezVous semantics.
+
+        public static ConfiguredTaskAwaitable RendezVous(this Task task, IAsyncScheduler scheduler)
+        {
+            return task.ConfigureAwait(true);
+        }
+
+        public static ConfiguredTaskAwaitable<T> RendezVous<T>(this Task<T> task, IAsyncScheduler scheduler)
+        {
+            return task.ConfigureAwait(true);
+        }
+    }
+}

+ 1 - 1
AsyncRx.NET/System.Reactive.Async/System/Reactive/Linq/Operators/Empty.cs

@@ -19,7 +19,7 @@ namespace System.Reactive.Linq
             {
                 ct.ThrowIfCancellationRequested();
 
-                await observer.OnCompletedAsync();
+                await observer.OnCompletedAsync().RendezVous(scheduler);
             }));
         }
     }

+ 2 - 2
AsyncRx.NET/System.Reactive.Async/System/Reactive/Linq/Operators/Range.cs

@@ -26,12 +26,12 @@ namespace System.Reactive.Linq
 
                 for (int i = start, end = start + count - 1; i <= end && !ct.IsCancellationRequested; i++)
                 {
-                    await observer.OnNextAsync(i);
+                    await observer.OnNextAsync(i).RendezVous(scheduler);
                 }
 
                 ct.ThrowIfCancellationRequested();
 
-                await observer.OnCompletedAsync();
+                await observer.OnCompletedAsync().RendezVous(scheduler);
             }));
         }
     }

+ 2 - 2
AsyncRx.NET/System.Reactive.Async/System/Reactive/Linq/Operators/Return.cs

@@ -22,11 +22,11 @@ namespace System.Reactive.Linq
             {
                 ct.ThrowIfCancellationRequested();
 
-                await observer.OnNextAsync(value);
+                await observer.OnNextAsync(value).RendezVous(scheduler);
 
                 ct.ThrowIfCancellationRequested();
 
-                await observer.OnCompletedAsync();
+                await observer.OnCompletedAsync().RendezVous(scheduler);
             }));
         }
     }