using Cysharp.Threading.Tasks.Internal; using System; using System.Threading; namespace Cysharp.Threading.Tasks.Linq { public static partial class UniTaskAsyncEnumerable { public static IUniTaskAsyncEnumerable Throw(Exception exception) { return new Throw(exception); } } internal class Throw : IUniTaskAsyncEnumerable { readonly Exception exception; public Throw(Exception exception) { this.exception = exception; } public IUniTaskAsyncEnumerator GetAsyncEnumerator(CancellationToken cancellationToken = default) { return new _Throw(exception, cancellationToken); } class _Throw : IUniTaskAsyncEnumerator { readonly Exception exception; CancellationToken cancellationToken; public _Throw(Exception exception, CancellationToken cancellationToken) { this.exception = exception; this.cancellationToken = cancellationToken; } public TValue Current => default; public UniTask MoveNextAsync() { cancellationToken.ThrowIfCancellationRequested(); return UniTask.FromException(exception); } public UniTask DisposeAsync() { return default; } } } }