Forráskód Böngészése

Reducing exceptions in Empty, Return, Throw.

Bart De Smet 8 éve
szülő
commit
d12150eb59

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

@@ -36,9 +36,10 @@ namespace System.Reactive.Linq
 
             return scheduler.ScheduleAsync(async ct =>
             {
-                ct.ThrowIfCancellationRequested();
-
-                await observer.OnCompletedAsync().RendezVous(scheduler, ct);
+                if (!ct.IsCancellationRequested)
+                {
+                    await observer.OnCompletedAsync().RendezVous(scheduler, ct);
+                }
             });
         }
     }

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

@@ -36,11 +36,13 @@ namespace System.Reactive.Linq
 
             return scheduler.ScheduleAsync(async ct =>
             {
-                ct.ThrowIfCancellationRequested();
+                if (ct.IsCancellationRequested)
+                    return;
 
                 await observer.OnNextAsync(value).RendezVous(scheduler, ct);
 
-                ct.ThrowIfCancellationRequested();
+                if (ct.IsCancellationRequested)
+                    return;
 
                 await observer.OnCompletedAsync().RendezVous(scheduler, ct);
             });

+ 4 - 3
AsyncRx.NET/System.Reactive.Async.Linq/System/Reactive/Linq/Operators/Throw.cs

@@ -41,9 +41,10 @@ namespace System.Reactive.Linq
 
             return scheduler.ScheduleAsync(async ct =>
             {
-                ct.ThrowIfCancellationRequested();
-
-                await observer.OnErrorAsync(error).RendezVous(scheduler, ct);
+                if (!ct.IsCancellationRequested)
+                {
+                    await observer.OnErrorAsync(error).RendezVous(scheduler, ct);
+                }
             });
         }
     }