Ejemplo n.º 1
0
        public static async UniTaskVoid SubscribeCore <TSource>(IUniTaskAsyncEnumerable <TSource> source, Func <TSource, UniTaskVoid> onNext, Action <Exception> onError, Action onCompleted, CancellationToken cancellationToken)
        {
            var e = source.GetAsyncEnumerator(cancellationToken);

            try
            {
                while (await e.MoveNextAsync())
                {
                    onNext(e.Current).Forget();
                }
                onCompleted();
            }
            catch (Exception ex)
            {
                if (onError == NopError)
                {
                    UniTaskScheduler.PublishUnobservedTaskException(ex);
                    return;
                }

                if (ex is OperationCanceledException)
                {
                    return;
                }

                onError(ex);
            }
            finally
            {
                if (e != null)
                {
                    await e.DisposeAsync();
                }
            }
        }
Ejemplo n.º 2
0
        public static async UniTaskVoid SubscribeCore <TSource>(IUniTaskAsyncEnumerable <TSource> source,
                                                                IObserver <TSource> observer, CancellationToken cancellationToken)
        {
            var e = source.GetAsyncEnumerator(cancellationToken);

            try {
                while (await e.MoveNextAsync())
                {
                    try {
                        observer.OnNext(e.Current);
                    }
                    catch (Exception ex) {
                        UniTaskScheduler.PublishUnobservedTaskException(ex);
                    }
                }

                observer.OnCompleted();
            }
            catch (Exception ex) {
                if (ex is OperationCanceledException)
                {
                    return;
                }

                observer.OnError(ex);
            }
            finally {
                if (e != null)
                {
                    await e.DisposeAsync();
                }
            }
        }
 public void SetException(Exception exception)
 {
     UniTaskScheduler.PublishUnobservedTaskException(exception);
 }