diff --git a/async-enumerable-dotnet-test/PrefetchTest.cs b/async-enumerable-dotnet-test/PrefetchTest.cs index 081c4ce..40e69f0 100644 --- a/async-enumerable-dotnet-test/PrefetchTest.cs +++ b/async-enumerable-dotnet-test/PrefetchTest.cs @@ -3,6 +3,8 @@ // See LICENSE file in the project root for full license information. using System; +using System.Threading; +using System.Threading.Tasks; using Xunit; using async_enumerable_dotnet; @@ -69,5 +71,13 @@ await AsyncEnumerable.Interval(1, 5, TimeSpan.FromMilliseconds(200)) .Take(1) .AssertResult(1L); } + + [Fact] + public async void Cancel() + { + await AsyncEnumerable.FromTask(Task.FromCanceled(new CancellationToken(true))) + .Prefetch(1) + .AssertFailure(typeof(OperationCanceledException)); + } } } diff --git a/async-enumerable-dotnet/impl/Prefetch.cs b/async-enumerable-dotnet/impl/Prefetch.cs index 535c3a0..e477562 100644 --- a/async-enumerable-dotnet/impl/Prefetch.cs +++ b/async-enumerable-dotnet/impl/Prefetch.cs @@ -93,6 +93,11 @@ private void SourceHandler(Task t) _error = ExceptionHelper.Extract(t.Exception); _done = true; } + else if (t.IsCanceled) + { + _error = new OperationCanceledException(); + _done = true; + } else if (t.Result) { _queue.Enqueue(_source.Current);