瀏覽代碼

Improving cancellation of Range.

Bart De Smet 8 年之前
父節點
當前提交
4d671dd7a5
共有 1 個文件被更改,包括 4 次插入2 次删除
  1. 4 2
      AsyncRx.NET/System.Reactive.Async.Linq/System/Reactive/Linq/Operators/Range.cs

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

@@ -43,14 +43,16 @@ namespace System.Reactive.Linq
 
 
             return scheduler.ScheduleAsync(async ct =>
             return scheduler.ScheduleAsync(async ct =>
             {
             {
-                ct.ThrowIfCancellationRequested();
+                if (ct.IsCancellationRequested)
+                    return;
 
 
                 for (int i = start, end = start + count - 1; i <= end && !ct.IsCancellationRequested; i++)
                 for (int i = start, end = start + count - 1; i <= end && !ct.IsCancellationRequested; i++)
                 {
                 {
                     await observer.OnNextAsync(i).RendezVous(scheduler, ct);
                     await observer.OnNextAsync(i).RendezVous(scheduler, ct);
                 }
                 }
 
 
-                ct.ThrowIfCancellationRequested();
+                if (ct.IsCancellationRequested)
+                    return;
 
 
                 await observer.OnCompletedAsync().RendezVous(scheduler, ct);
                 await observer.OnCompletedAsync().RendezVous(scheduler, ct);
             });
             });