Last active
January 2, 2016 08:59
-
-
Save shiftkey/8280498 to your computer and use it in GitHub Desktop.
A quick and dirty demonstration of Window in Rx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Reactive.Linq; | |
namespace SlidingWindow | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var random = new Random(); | |
Observable.Generate(0, i => true, i => i, i => random.Next(100), i => TimeSpan.FromMilliseconds(random.Next(150))) | |
.Where(x => x > 50) | |
.Window(TimeSpan.FromSeconds(1)) | |
.Subscribe(next => next.Count() | |
.Where(x => x > 5) | |
.Subscribe(c => Console.WriteLine("Got {0} events at {1}", c, Environment.TickCount))); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment