public async Task ProduceConsumeSlowly2()
        {
            var scheduler = new TestAsyncScheduler();

            var result = await scheduler.RunAsync(async() =>
            {
                return(await scheduler.ProduceSlowly(
                           10.Seconds(),
                           10.Seconds(),
                           10.Seconds(),
                           10.Seconds(),
                           10.Seconds())
                       .DropOnBackpressure()
                       .ConsumeSlowly(scheduler,
                                      20.Seconds(),
                                      20.Seconds(),
                                      20.Seconds(),
                                      20.Seconds(),
                                      20.Seconds()));
            });

            result
            .Should().Equal(
                (0, 30.Seconds()),
                (2, 50.Seconds()),
                (4, 70.Seconds()));
        }
Пример #2
0
        public async Task ProduceSlowlyMultiple()
        {
            var scheduler = new TestAsyncScheduler();

            var result = await scheduler.RunAsync(async() =>
            {
                var inner1 = scheduler.ProduceSlowly(
                    10.Seconds(),
                    10.Seconds(),
                    10.Seconds(),
                    10.Seconds(),
                    10.Seconds());

                var inner2 = inner1
                             .Select(i => i + 10);

                return(await new [] { inner1, inner2 }
                       .ToAsyncObservable()
                       .Merge()
                       .ConsumeFast(scheduler));
            });

            result
            .Should().Equal(
                (0, 10.Seconds()),
                (10, 10.Seconds()),
                (1, 20.Seconds()),
                (11, 20.Seconds()),
                (2, 30.Seconds()),
                (12, 30.Seconds()),
                (3, 40.Seconds()),
                (13, 40.Seconds()),
                (4, 50.Seconds()),
                (14, 50.Seconds()));
        }
        public async Task ProduceConsumeSlowly()
        {
            var scheduler = new TestAsyncScheduler();

            var result = await scheduler.RunAsync(async() =>
            {
                return(await scheduler.ProduceSlowly(
                           10.Seconds(),
                           10.Seconds(),
                           10.Seconds(),
                           10.Seconds(),
                           10.Seconds())
                       .ConsumeSlowly(scheduler,
                                      10.Seconds(),
                                      10.Seconds(),
                                      10.Seconds(),
                                      10.Seconds(),
                                      10.Seconds()));
            });

            result
            .Should().Equal(
                (0, 20.Seconds()),
                (1, 40.Seconds()),
                (2, 60.Seconds()),
                (3, 80.Seconds()),
                (4, 100.Seconds()));
        }
Пример #4
0
        public async Task ProduceSlowly()
        {
            var scheduler = new TestAsyncScheduler();

            var result = await scheduler.RunAsync(async() =>
            {
                return(await scheduler.ProduceSlowly(
                           10.Seconds(),
                           10.Seconds(),
                           10.Seconds(),
                           10.Seconds(),
                           10.Seconds())
                       .SampleFirst(20.Seconds(), scheduler)
                       .ConsumeFast(scheduler));
            });

            result
            .Should().Equal(
                (0, 10.Seconds()),
                (2, 30.Seconds()),
                (4, 50.Seconds()));
        }
Пример #5
0
        public async Task SlowProduce()
        {
            string result = "";

            var scheduler = new TestAsyncScheduler();

            await scheduler.RunAsync(async() =>
            {
                return(await scheduler.ProduceSlowly(
                           10.Seconds(),
                           10.Seconds(),
                           10.Seconds(),
                           10.Seconds(),
                           10.Seconds())
                       .Do(i => result += i)
                       .Prefetch()
                       .Do(i => result += i)
                       .ConsumeFast(scheduler));
            });

            result
            .Should().Be("0011223344");
        }