BuffersAndSlidingWindows.Program.BufferingHiRateChatMessages C# (CSharp) Method

BufferingHiRateChatMessages() private static method

private static BufferingHiRateChatMessages ( ) : void
return void
        private static void BufferingHiRateChatMessages()
        {
            Demo.DisplayHeader("The Buffer operator - can be used to slow high-rate stream by taking it by chunks");

            var coldMessages = Observable.Interval(TimeSpan.FromMilliseconds(50))
                .Take(4)
                .Select(x => "Message " + x);

            IObservable<string> messages =
                coldMessages.Concat(
                     coldMessages.DelaySubscription(TimeSpan.FromMilliseconds(200)))
                    .Publish()
                    .RefCount();

            messages.Buffer(messages.Throttle(TimeSpan.FromMilliseconds(100)))
                .SelectMany((b, i) => b.Select(m => string.Format("Buffer {0} - {1}", i, m)))
                .RunExample("Hi-Rate Messages");
        }