当前位置: 首页>>代码示例>>C#>>正文


C# Subject.OnError方法代码示例

本文整理汇总了C#中Subject.OnError方法的典型用法代码示例。如果您正苦于以下问题:C# Subject.OnError方法的具体用法?C# Subject.OnError怎么用?C# Subject.OnError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Subject的用法示例。


在下文中一共展示了Subject.OnError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DeterministicDisposal

        private static void DeterministicDisposal()
        {
            Demo.DisplayHeader("The Using operator will make sure that the resource is disposed no matter what caused the observable to stop");

            Subject<int> subject = new Subject<int>();
            var observable =
                Observable.Using(() => Disposable.Create(() => { Console.WriteLine("DISPOSED"); }),
                    _ => subject);

            Console.WriteLine();
            Console.WriteLine("Disposed when completed");
            observable.SubscribeConsole();
            subject.OnCompleted();

            Console.WriteLine();
            Console.WriteLine("Disposed when error occurs");
            subject = new Subject<int>();
            observable.SubscribeConsole();
            subject.OnError(new Exception("error"));

            Console.WriteLine();
            Console.WriteLine("Disposed when subscription disposed");
            subject = new Subject<int>();
            var subscription =
                observable.SubscribeConsole();
            subscription.Dispose();
        }
开发者ID:tamirdresher,项目名称:RxInAction,代码行数:27,代码来源:Program.cs

示例2: OAPHShouldRethrowErrors

        public void OAPHShouldRethrowErrors()
        {
            var input = new Subject<int>();
            var sched = new TestScheduler();

            var fixture = new ObservableAsPropertyHelper<int>(input,
                _ => { }, -5, sched);

            Assert.AreEqual(-5, fixture.Value);
            (new[] { 1, 2, 3, 4 }).Run(x => input.OnNext(x));

            sched.Run();

            Assert.AreEqual(4, fixture.Value);

            input.OnError(new Exception("Die!"));

            sched.Run();

            try {
                Assert.AreEqual(4, fixture.Value);
            } catch {
                return;
            }
            Assert.Fail("We should've threw there");
        }
开发者ID:charles-cai,项目名称:ReactiveXaml,代码行数:26,代码来源:ObservableAsPropertyHelperTest.cs

示例3: CanExecuteExceptionShouldntPermabreakCommands

        public void CanExecuteExceptionShouldntPermabreakCommands()
        {
            var canExecute = new Subject<bool>();
            var fixture = CreateCommand(canExecute);

            var exceptions = new List<Exception>();
            var canExecuteStates = new List<bool>();
            fixture.CanExecuteObservable.Subscribe(canExecuteStates.Add);
            fixture.ThrownExceptions.Subscribe(exceptions.Add);

            canExecute.OnNext(false);
            Assert.False(fixture.CanExecute(null));

            canExecute.OnNext(true);
            Assert.True(fixture.CanExecute(null));

            canExecute.OnError(new Exception("Aieeeee!"));

            // The command should latch to false forever
            Assert.False(fixture.CanExecute(null));

            Assert.AreEqual(1, exceptions.Count);
            Assert.AreEqual("Aieeeee!", exceptions[0].Message);

            Assert.AreEqual(false, canExecuteStates[canExecuteStates.Count - 1]);
            Assert.AreEqual(true, canExecuteStates[canExecuteStates.Count - 2]);
        }
开发者ID:OlexaLe,项目名称:RxLite,代码行数:27,代码来源:ReactiveCommandTests.cs

示例4: Should_Complete_When_Update_Observable_Errors

        public void Should_Complete_When_Update_Observable_Errors()
        {
            var update = new Subject<Unit>();
            var target = new ExpressionObserver(() => 1, "Foo", update);
            var completed = false;

            target.Subscribe(_ => { }, () => completed = true);
            update.OnError(new Exception());

            Assert.True(completed);
        }
开发者ID:jkoritzinsky,项目名称:Avalonia,代码行数:11,代码来源:ExpressionObserverTests_Lifetime.cs

示例5: TakeErrorTest

 public void TakeErrorTest()
 {
     var subject = new Subject<string>();
     var result = new List<IValueOrError<string>>();
     subject
         .TakeError()
         .Subscribe(result.Add);
     subject.OnNext("a");
     subject.OnError(new Exception("error!"));
     result.Count.Is(2);
     result[0].IsError.IsFalse();
     result[1].IsError.IsTrue();
 }
开发者ID:syo00,项目名称:LightWands,代码行数:13,代码来源:ObservableExtensionsTest.cs

示例6: ResolvedEventDispatcher

        public ResolvedEventDispatcher(
            IEventStoreConnection eventStore,
            ISerializer serializer,
            ICheckpointRepository checkpoints,
            Func<ISerializer, ResolvedEvent, bool, CancellationToken, Task> dispatchResolvedEvent,
            Action onCaughtUp = null,
            string streamId = null,
            UserCredentials userCredentials = null)
        {
            _isStarted = new InterlockedBoolean();
            _isDisposed = new InterlockedBoolean();

            _eventStore = eventStore;
            _serializer = serializer;
            _checkpoints = checkpoints;
            _dispatchResolvedEvent = dispatchResolvedEvent;
            _onCaughtUp = onCaughtUp ?? (() => { });
            _streamId = streamId;
            _userCredentials = userCredentials;
            _projectedEvents = new Subject<ResolvedEvent>();

            _queue = new SimpleQueue(async (resolvedEvent, token) =>
            {
                try
                {
                    await _dispatchResolvedEvent(_serializer, resolvedEvent, _subscription.IsSubscribedToAll, _disposed.Token);
                }
                catch(Exception ex)
                {
                    _projectedEvents.OnError(ex);
                    throw;
                }

                if(_isDisposed.Value)
                {
                    return;
                }

                _projectedEvents.OnNext(resolvedEvent);

            }, _disposed.Token);
        }
开发者ID:modulexcite,项目名称:Obsolete-Cedar,代码行数:42,代码来源:ResolvedEventDispatcher.cs

示例7: SubjectExample

        private static void SubjectExample()
        {
            Console.WriteLine("Subject:");
            var location = new Subject<Location>(); // Observable
            var reporter1 = CreateReporterWith("FixedGPS "); // Observer
            var reporter2 = CreateReporterWith("MobileGPS"); // Observer
            var subscription1 = location.Subscribe(reporter1);
            location.Subscribe(reporter2);

            location.OnNext(new Location(47.6456, -123.1312));
            location.OnNext(new Location(31.6677, -11.1199));

            subscription1.Dispose();

            location.OnNext(new Location(84.6677, -21.1023));
            location.OnError(new LocationUnknownException());
            location.OnCompleted();

            ConsoleUtils.WaitForEnter();
        }
开发者ID:DotNetHH,项目名称:hhcsharp-reactive-extensions,代码行数:20,代码来源:Program.cs

示例8: NoThrownExceptionsSubscriberEqualsOAPHDeath

        public void NoThrownExceptionsSubscriberEqualsOAPHDeath()
        {
            (new TestScheduler()).With(sched => {
                var input = new Subject<int>();
                var fixture = new ObservableAsPropertyHelper<int>(input, _ => { }, -5);

                Assert.Equal(-5, fixture.Value);
                (new[] { 1, 2, 3, 4 }).Run(x => input.OnNext(x));

                input.OnError(new Exception("Die!"));

                bool failed = true;
                try {
                    sched.Start();
                } catch (Exception ex) {
                    failed = ex.InnerException.Message != "Die!";
                }

                Assert.False(failed);
                Assert.Equal(4, fixture.Value);
            });
        }
开发者ID:jorik041,项目名称:ReactiveUI,代码行数:22,代码来源:ObservableAsPropertyHelperTest.cs

示例9: SetToError

        public void SetToError()
        {
            bool invoked = false;
            var status = ConnectionStatus.Pending;
            var subject = new Subject<int>();
            Exception exception;

            var subscription = subject.MonitorStatus().Subscribe(s =>
            {
                invoked = true;
                status = s;
            }, ex =>
               {
                   exception = ex;
               });

            subject.OnError(new Exception("Test"));
            subscription.Dispose();

            Assert.IsTrue(invoked, "No update has been received");
            Assert.AreEqual(ConnectionStatus.Errored, status, "Status should be ConnectionStatus.Faulted");
        }
开发者ID:KingKnecht,项目名称:DynamicData,代码行数:22,代码来源:MonitorStatusFixture.cs

示例10: ObserveOnTest

        public void ObserveOnTest()
        {
            var xs = Observable.Range(1, 10)
                .ObserveOn(Scheduler.ThreadPool)
                .ToArrayWait();

            xs.OrderBy(x => x).IsCollection(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);

            var s = new Subject<int>();

            var list = new List<Notification<int>>();
            s.ObserveOn(Scheduler.Immediate).Materialize().Subscribe(list.Add);

            s.OnError(new Exception());

            list[0].Kind.Is(NotificationKind.OnError);

            s = new Subject<int>();
            s.ObserveOn(Scheduler.Immediate).Materialize().Subscribe(list.Add);

            s.OnCompleted();
            list[1].Kind.Is(NotificationKind.OnCompleted);
        }
开发者ID:createdbyx,项目名称:UniRx,代码行数:23,代码来源:Observable.ConcurrencyTest.cs

示例11: UseObserverTest2

 public void UseObserverTest2()
 {
     var subject = new Subject<string>();
     var result = new List<string>();
     subject
         .UseObserver((observer, value, i) =>
         {
             observer.OnNext(value);
         },
         (error, observer) =>
         {
             observer.OnNext(error.Message);
         },
         observer =>
         {
             observer.OnNext("end");
         })
         .Subscribe(result.Add);
     subject.OnNext("a");
     subject.OnError(new Exception("error!"));
     subject.OnCompleted();
     result.Is("a", "error!");
 }
开发者ID:syo00,项目名称:LightWands,代码行数:23,代码来源:ObservableExtensionsTest.cs

示例12: OAPHShouldRethrowErrors

        public void OAPHShouldRethrowErrors()
        {
            var input = new Subject<int>();
            var sched = new TestScheduler();

            var fixture = new ObservableAsPropertyHelper<int>(input, _ => { }, -5, sched);
            var errors = new List<Exception>();

            Assert.Equal(-5, fixture.Value);
            (new[] { 1, 2, 3, 4 }).Run(x => input.OnNext(x));

            fixture.ThrownExceptions.Subscribe(errors.Add);

            sched.Start();

            Assert.Equal(4, fixture.Value);

            input.OnError(new Exception("Die!"));

            sched.Start();

            Assert.Equal(4, fixture.Value);
            Assert.Equal(1, errors.Count);
        }
开发者ID:nestalk,项目名称:ReactiveUI,代码行数:24,代码来源:ObservableAsPropertyHelperTest.cs

示例13: FinishedSourceToReadOnlyReactiveProperty

 public void FinishedSourceToReadOnlyReactiveProperty()
 {
     SetScehdulerForImport();
     // pattern of OnCompleted
     {
         var source = Observable.Return(9);
         var rxProp = source.ToReadOnlyReactiveProperty();
         var notifications = rxProp.Record().Notifications;
         notifications.IsCollection(Notification.CreateOnNext(9), Notification.CreateOnCompleted<int>());
         rxProp.Record().Notifications.IsCollection(
             Notification.CreateOnNext(9),
             Notification.CreateOnCompleted<int>());
     }
     // pattern of OnError
     {
         // after
         {
             var ex = new Exception();
             var source = Observable.Throw<int>(ex);
             var rxProp = source.ToReadOnlyReactiveProperty();
             var notifications = rxProp.Record().Notifications;
             notifications.IsCollection(Notification.CreateOnError<int>(ex));
             rxProp.Record().Notifications.IsCollection(Notification.CreateOnError<int>(ex));
         }
         // immediate
         {
             var ex = new Exception();
             var source = new Subject<int>();
             var rxProp = source.ToReadOnlyReactiveProperty();
             var record = rxProp.Record();
             source.OnError(new Exception());
             var notifications = record.Notifications;
             notifications.Count.Is(1);
             notifications[0].Kind.Is(NotificationKind.OnError);
             rxProp.Record().Notifications[0].Kind.Is(NotificationKind.OnError);
         }
     }
     UniRx.Scheduler.SetDefaultForUnity();
 }
开发者ID:neuecc,项目名称:UniRx,代码行数:39,代码来源:TestImporter.cs

示例14: NoSubscriberOfThrownExceptionsEqualsDeath

        public void NoSubscriberOfThrownExceptionsEqualsDeath()
        {
            (new TestScheduler()).With(sched => {
                var canExecute = new Subject<bool>();
                var fixture = createCommand(canExecute);

                canExecute.OnNext(true);
                canExecute.OnError(new Exception("Aieeeee!"));

                bool failed = true;
                try {
                    sched.Start();
                    Assert.True(fixture.CanExecute(null));
                } catch (Exception ex) {
                    failed = (ex.InnerException.Message != "Aieeeee!");
                }

                Assert.False(failed);
            });
        }
开发者ID:StanislawSwierc,项目名称:ReactiveUI,代码行数:20,代码来源:ReactiveCommandTest.cs

示例15: SubjectSubscribeTest

        public void SubjectSubscribeTest()
        {
            var subject = new Subject<int>();
            var listA = new List<int>();
            var listB = new List<int>();
            var listC = new List<int>();
            subject.HasObservers.IsFalse();

            var listASubscription = subject.Subscribe(x => listA.Add(x));
            subject.HasObservers.IsTrue();
            subject.OnNext(1);
            listA[0].Is(1);

            var listBSubscription = subject.Subscribe(x => listB.Add(x));
            subject.HasObservers.IsTrue();
            subject.OnNext(2);
            listA[1].Is(2);
            listB[0].Is(2);

            var listCSubscription = subject.Subscribe(x => listC.Add(x));
            subject.HasObservers.IsTrue();
            subject.OnNext(3);
            listA[2].Is(3);
            listB[1].Is(3);
            listC[0].Is(3);

            listASubscription.Dispose();
            subject.HasObservers.IsTrue();
            subject.OnNext(4);
            listA.Count.Is(3);
            listB[2].Is(4);
            listC[1].Is(4);

            listCSubscription.Dispose();
            subject.HasObservers.IsTrue();
            subject.OnNext(5);
            listC.Count.Is(2);
            listB[3].Is(5);

            listBSubscription.Dispose();
            subject.HasObservers.IsFalse();
            subject.OnNext(6);
            listB.Count.Is(4);

            var listD = new List<int>();
            var listE = new List<int>();

            subject.Subscribe(x => listD.Add(x));
            subject.HasObservers.IsTrue();
            subject.OnNext(1);
            listD[0].Is(1);

            subject.Subscribe(x => listE.Add(x));
            subject.HasObservers.IsTrue();
            subject.OnNext(2);
            listD[1].Is(2);
            listE[0].Is(2);

            subject.Dispose();

            AssertEx.Throws<ObjectDisposedException>(() => subject.OnNext(0));
            AssertEx.Throws<ObjectDisposedException>(() => subject.OnError(new Exception()));
            AssertEx.Throws<ObjectDisposedException>(() => subject.OnCompleted());
        }
开发者ID:ragcat,项目名称:UniRx,代码行数:64,代码来源:UnitTests.cs


注:本文中的Subject.OnError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。