Răsfoiți Sursa

Improving Take cancellation.

Bart De Smet 8 ani în urmă
părinte
comite
8726a40dc4

+ 5 - 4
AsyncRx.NET/System.Reactive.Async.Linq/System/Reactive/Linq/Operators/Take.cs

@@ -128,11 +128,12 @@ namespace System.Reactive.Linq
                         Synchronize(observer, gate),
                         await scheduler.ScheduleAsync(async ct =>
                         {
-                            ct.ThrowIfCancellationRequested();
-
-                            using (await gate.LockAsync().RendezVous(scheduler, ct))
+                            if (!ct.IsCancellationRequested)
                             {
-                                await observer.OnCompletedAsync().RendezVous(scheduler, ct);
+                                using (await gate.LockAsync().RendezVous(scheduler, ct))
+                                {
+                                    await observer.OnCompletedAsync().RendezVous(scheduler, ct);
+                                }
                             }
                         }, duration).ConfigureAwait(false)
                     );