Skip to content

Instantly share code, notes, and snippets.

@shiftkey
Last active January 2, 2016 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shiftkey/8280498 to your computer and use it in GitHub Desktop.
Save shiftkey/8280498 to your computer and use it in GitHub Desktop.
A quick and dirty demonstration of Window in Rx
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