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


C# Subject.OnNext方法代码示例

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


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

示例1: AutoPersistHelperSavesOnInterval

        public void AutoPersistHelperSavesOnInterval()
        {
            (new TestScheduler()).With(sched => {
                var fixture = new TestFixture();
                var manualSave = new Subject<Unit>();

                int timesSaved = 0;
                fixture.AutoPersist(x => { timesSaved++; return Observable.Return(Unit.Default); }, manualSave, TimeSpan.FromMilliseconds(100));

                // No changes = no saving
                sched.AdvanceByMs(2 * 100);
                Assert.Equal(0, timesSaved);

                // Change = one save
                fixture.IsNotNullString = "Foo";
                sched.AdvanceByMs(2 * 100);
                Assert.Equal(1, timesSaved);

                // Two fast changes = one save
                fixture.IsNotNullString = "Foo";
                fixture.IsNotNullString = "Bar";
                sched.AdvanceByMs(2 * 100);
                Assert.Equal(2, timesSaved);

                // Trigger save twice = one save
                manualSave.OnNext(Unit.Default);
                manualSave.OnNext(Unit.Default);
                sched.AdvanceByMs(2 * 100);
                Assert.Equal(3, timesSaved);
            });
        }
开发者ID:KimCM,项目名称:ReactiveUI,代码行数:31,代码来源:AutoPersistHelperTest.cs

示例2: UseObserverTest1

 public void UseObserverTest1()
 {
     var subject = new Subject<string>();
     var result = new List<Tuple<int, string>>();
     subject
         .Select(x => new Tuple<int, string>(0, x))
         .UseObserver((observer, value, i) =>
         {
             observer.OnNext(new Tuple<int, string>(i, value.Item2));
         },
         null,
         observer =>
         {
             observer.OnNext(new Tuple<int, string>(-1, "end"));
         })
         .Subscribe(result.Add);
     subject.OnNext("a");
     subject.OnNext("b");
     subject.OnNext("c");
     subject.OnCompleted();
     result.Is(
         new Tuple<int, string>(0, "a"),
         new Tuple<int, string>(1, "b"),
         new Tuple<int, string>(2, "c"),
         new Tuple<int, string>(-1, "end"));
 }
开发者ID:syo00,项目名称:LightWands,代码行数:26,代码来源:ObservableExtensionsTest.cs

示例3: Main

    protected override void Main()
    {
      TraceLine(Instructions.PressAnyKeyToCancel);

      var queries = new Subject<IObservable<string>>();

      var zipped = queries
        .Zip()
        .Select(list => list.Aggregate(string.Empty, (acc, cur) => acc += cur + " "))
        .Take(3);

      using (zipped.Subscribe(ConsoleOutput))
      {
        var xs = Observable.Interval(TimeSpan.FromSeconds(.5));
        var ys = Observable.Interval(TimeSpan.FromSeconds(1));
        var zs = Observable.Interval(TimeSpan.FromSeconds(1.5));

        queries.OnNext(xs.Select(value => Text.First + ' ' + value));
        queries.OnNext(ys.Select(value => Text.Second + ' ' + value));
        queries.OnNext(zs.Select(value => Text.Third + ' ' + value));
        queries.OnCompleted();

        WaitForKey();
      }
    }
开发者ID:ibebbs,项目名称:Rxx,代码行数:25,代码来源:ZipLab.cs

示例4: ReplayFresh_provides_a_fresh_observable

        public async Task ReplayFresh_provides_a_fresh_observable()
        {
            var sourceSubject = new Subject<int>();

            var replayed = sourceSubject
                .ReplayFresh(1)
                .RefCount();

            using (replayed.Subscribe())
            {
                var task1 = replayed
                    .FirstAsync()
                    .ToTask();

                sourceSubject.OnNext(36);

                (await task1).Should().Be(36);
                (await replayed.FirstAsync().ToTask()).Should().Be(36);
            }

            var task2 = replayed
                .FirstAsync()
                .ToTask();

            sourceSubject.OnNext(37);

            (await task2).Should().Be(37);
        }
开发者ID:ExRam,项目名称:ExRam.ReactiveCollections,代码行数:28,代码来源:ObservableExtensionsTest.cs

示例5: Receive

        public IObservable<string> Receive(byte[] buffer, IScheduler scheduler)
        {
            return Observable.Create<string>(observer =>
                {
                    var disposable = new CompositeDisposable();
                    this.connectionToken.SocketEvent.SetBuffer(buffer, 0, buffer.Length);
                    var subject = new Subject<Unit>();

                    var disposableEventSubscription = connectionToken.SocketEvent.Completed.Subscribe(_ =>
                    {
                        if (SendNotificationToObserver(observer, connectionToken.SocketEvent))
                        {
                            subject.OnNext(Unit.Default);
                        }
                    });

                    var disposableActions = subject.ObserveOn(scheduler).Subscribe(_ =>
                    {
                        if (!connectionToken.Socket.ReceiveAsync(connectionToken.SocketEvent))
                        {
                            if (SendNotificationToObserver(observer, connectionToken.SocketEvent))
                            {
                                subject.OnNext(Unit.Default);
                            }
                        }
                    });

                    subject.OnNext(Unit.Default);

                    disposable.Add(disposableEventSubscription);
                    disposable.Add(disposableActions);

                    return disposable;
                });
        }
开发者ID:vgrigoriu,项目名称:Redis.SilverlightClient,代码行数:35,代码来源:RedisReceiver.cs

示例6: last_value_is_received_after_completed_if_any_connection_is_disposed

        public void last_value_is_received_after_completed_if_any_connection_is_disposed()
        {
            Subject<int> subject = new Subject<int>();

            var stats = new StatsObserver<int>();

            var obs = subject.Prune();
            var connectionA = obs.Connect();
            var connectionB = obs.Connect();

            subject.OnNext(1);
            subject.OnNext(2);
            subject.OnNext(3);

            connectionA.Dispose();

            subject.OnCompleted();

            connectionB.Dispose();

            obs.Subscribe(stats);

            Assert.IsFalse(stats.NextCalled);
            Assert.IsFalse(stats.CompletedCalled);
        }
开发者ID:richardszalay,项目名称:raix,代码行数:25,代码来源:PruneFixture.cs

示例7: SimpleDelayWithDrop

        public void SimpleDelayWithDrop()
        {
            var receivedSignals = new List<int>();
            var subject = new Subject<int>();
            var scheduler = new TestScheduler();
            subject.UniqueThrottle(TimeSpan.FromTicks(25), scheduler).Subscribe(x => receivedSignals.Add(x));


            subject.OnNext(1);
            subject.OnNext(1);
            subject.OnNext(1);
            receivedSignals.Count.Should().Be(0);
            scheduler.AdvanceTo(24);
            subject.OnNext(1);
            subject.OnNext(1);
            subject.OnNext(1);
            receivedSignals.Count.Should().Be(0);

            scheduler.AdvanceTo(25);
            receivedSignals.Count.Should().Be(1);

            scheduler.AdvanceTo(50);
            subject.OnNext(1);
            receivedSignals.Count.Should().Be(1);

            scheduler.AdvanceTo(100);
            receivedSignals.Count.Should().Be(2);
        }
开发者ID:rog1039,项目名称:Rogero.RxExtensions,代码行数:28,代码来源:KeyedBufferTests.cs

示例8: AutoSuspendHelper

        public AutoSuspendHelper(UIApplicationDelegate appDelegate)
        {
            Reflection.ThrowIfMethodsNotOverloaded("AutoSuspendHelper", appDelegate,
                "FinishedLaunching", "OnActivated", "DidEnterBackground");

            RxApp.SuspensionHost.IsLaunchingNew = Observable.Never<Unit>();
            RxApp.SuspensionHost.IsResuming = _finishedLaunching.Select(_ => Unit.Default);
            RxApp.SuspensionHost.IsUnpausing = _activated.Select(_ => Unit.Default);

            var untimelyDeath = new Subject<Unit>();
            AppDomain.CurrentDomain.UnhandledException += (o,e) => untimelyDeath.OnNext(Unit.Default);

            RxApp.SuspensionHost.ShouldInvalidateState = untimelyDeath;

            RxApp.SuspensionHost.ShouldPersistState = _backgrounded.SelectMany(app => {
                var taskId = app.BeginBackgroundTask(new NSAction(() => untimelyDeath.OnNext(Unit.Default)));

                // NB: We're being force-killed, signal invalidate instead
                if (taskId == UIApplication.BackgroundTaskInvalid) {
                    untimelyDeath.OnNext(Unit.Default);
                    return Observable.Empty<IDisposable>();
                }

                return Observable.Return(Disposable.Create(() => app.EndBackgroundTask(taskId)));
            });
        }
开发者ID:journeyman,项目名称:ReactiveUI,代码行数:26,代码来源:AutoSuspendHelper.cs

示例9: Run

        public void Run()
        {
            var subject = new Subject<int>();

            subject.Select(x => x).Subscribe(x => { Console.WriteLine(x); throw new Exception(); }, ex =>
            {
                ShowStackTrace();
                Console.WriteLine("called ex 1");
                //throw ex;
            });

            try
            {
                subject.OnNext(2);
            }
            catch
            {
            }

            try
            {
                subject.OnNext(1);
            }
            catch
            {
            }
        }
开发者ID:MighteeCactus,项目名称:UniRx,代码行数:27,代码来源:Playground.cs

示例10: ProccessingTheSourceAndTheResult

        private static void ProccessingTheSourceAndTheResult()
        {
            Demo.DisplayHeader("The SelectMany operator - with resultSelector you can ");

            var roomsSubject = new Subject<ChatRoom>();

            IObservable<ChatRoom> rooms = roomsSubject.AsObservable();

            rooms
            .Log("Rooms")
            .SelectMany(r => r.Messages,
                (room, msg) => new ChatMessageViewModel(msg) {Room = room.Id})
            .Subscribe(vm => AddToDashboard(vm));

            var room1 = new Subject<ChatMessage>();
            roomsSubject.OnNext(new ChatRoom { Id = "Room1", Messages = room1 });

            room1.OnNext(new ChatMessage { Content = "First Message", Sender = "1" });
            room1.OnNext(new ChatMessage { Content = "Second Message", Sender = "1" });

            var room2 = new Subject<ChatMessage>();
            roomsSubject.OnNext(new ChatRoom { Id = "Room2", Messages = room2 });

            room2.OnNext(new ChatMessage { Content = "Hello World", Sender = "2" });
            room1.OnNext(new ChatMessage { Content = "Another Message", Sender = "1" });
        }
开发者ID:xgrommx,项目名称:RxInAction,代码行数:26,代码来源:ChatRoomsExample.cs

示例11: Zip

        public void Zip()
        {
            var a = new Subject<int>();
            var b = new Subject<int>();

            a.OnNext(10);
            b.OnNext(20);

            var l = Enumerable.Empty<Unit>().Select(_ => Notification.CreateOnNext(new { x = 0, y = 0 })).ToList();
            a.Zip(b, (x, y) => new { x, y }).Materialize().Subscribe(x => l.Add(x));

            a.OnNext(1000);
            b.OnNext(2000);

            a.OnCompleted();

            l.Count.Is(1); // OnNext

            a.OnNext(1001);
            l.Count.Is(1);

            b.OnNext(5);
            l.Count.Is(2); // Completed!

            l[1].Kind.Is(NotificationKind.OnCompleted);
        }
开发者ID:gameserver,项目名称:UniRx,代码行数:26,代码来源:Observable.ConcatTest.cs

示例12: BasicExperiment

    public void BasicExperiment()
    {
      var xs = new Subject<int>();
      var ys = new Subject<int>();
      var zs = new Subject<int>();

      IObservable<int> query = xs.AsOperational() + ys - zs;

      using (query.Subscribe(ConsoleOutput))
      {
        xs.OnNext(1);
        ys.OnNext(5);
        zs.OnNext(2);

        xs.OnNext(2);
        ys.OnNext(6);
        zs.OnNext(3);

        xs.OnNext(3);
        xs.OnNext(4);

        zs.OnNext(4);
        zs.OnNext(5);

        ys.OnNext(7);
        ys.OnNext(8);

        WaitForKey();
      }
    }
开发者ID:ibebbs,项目名称:Rxx,代码行数:30,代码来源:OperationalLab.cs

示例13: AdvancedExperiment

    public void AdvancedExperiment()
    {
      var xs = new Subject<int>();
      var ys = new Subject<int>();
      var zs = new Subject<int>();

      // Define an operational factory so that operators are only specified once.
      var o = (Func<IObservable<int>, OperationalObservable<int>>)
        (source => source.AsOperational(
          add: (left, right) => left + (right * 5),
          subtract: (left, right) => left - right,
          multiply: (left, right) => left * right,
          divide: (left, right) => (left * 2) / right,
          negative: value => -value));

      IObservable<int> query = (-o(xs) * 2) + ys - (o(zs) / 4);

      using (query.Subscribe(ConsoleOutput))
      {
        xs.OnNext(1);
        ys.OnNext(5);
        zs.OnNext(4);

        xs.OnNext(2);
        ys.OnNext(6);
        zs.OnNext(8);

        xs.OnNext(3);
        ys.OnNext(7);
        zs.OnNext(12);

        WaitForKey();
      }
    }
开发者ID:ibebbs,项目名称:Rxx,代码行数:34,代码来源:OperationalLab.cs

示例14: CombineLatest

        public void CombineLatest()
        {
            var a = new Subject<int>();
            var b = new Subject<int>();

            a.OnNext(10);
            b.OnNext(20);

            var l = Enumerable.Empty<Unit>().Select(_ => Notification.CreateOnNext(new { x = 0, y = 0 })).ToList();
            a.CombineLatest(b, (x, y) => new { x, y }).Materialize().Subscribe(x => l.Add(x));

            a.OnNext(1000);
            b.OnNext(2000);
            l[0].Value.Is(new { x = 1000, y = 2000 });

            b.OnNext(3000);
            l[1].Value.Is(new { x = 1000, y = 3000 });

            a.OnNext(5000);
            l[2].Value.Is(new { x = 5000, y = 3000 });

            a.OnCompleted();
            l.Count.Is(3);

            a.OnNext(1001);
            l.Count.Is(3);

            b.OnNext(5);
            l[3].Value.Is(new { x = 5000, y = 5 });
            b.OnNext(500);
            l[4].Value.Is(new { x = 5000, y = 500 });

            b.OnCompleted();
            l[5].Kind.Is(NotificationKind.OnCompleted);
        }
开发者ID:MighteeCactus,项目名称:UniRx,代码行数:35,代码来源:Observable.ConcatTest.cs

示例15: Main

        static void Main(string[] args)
        {
            Subject<int> numbers = new Subject<int>();
            var historicalScheduler = new System.Reactive.Concurrency.HistoricalScheduler(new DateTime(2015, 11, 21, 17, 10, 0));
            historicalScheduler.Schedule(new DateTime(2015, 11, 21, 17, 10, 0), () => numbers.OnNext(1));
            historicalScheduler.Schedule(new DateTime(2015, 11, 21, 17, 11, 0), () => numbers.OnNext(2));
            historicalScheduler.Schedule(new DateTime(2015, 11, 21, 17, 32, 0), () => numbers.OnNext(3));
            historicalScheduler.Schedule(new DateTime(2015, 11, 21, 17, 39, 0), () => numbers.OnNext(4));
            historicalScheduler.Schedule(new DateTime(2015, 11, 21, 17, 51, 0), () => historicalScheduler.Stop());

            numbers.AsObservable()
                .Buffer(TimeSpan.FromMinutes(20), historicalScheduler)
                .Subscribe(buffer =>
                {
                    Console.WriteLine("time is: {0}", historicalScheduler.Now);
                    Console.WriteLine("Buffer:");
                    foreach (var x in buffer)
                    {
                        Console.WriteLine("\t{0}", x);
                    }
                });

            historicalScheduler.Start();

            Console.WriteLine("Press <enter> to continue");
            Console.ReadLine();
        }
开发者ID:tamirdresher,项目名称:Rx101,代码行数:27,代码来源:Program.cs


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