Skip to content

Instantly share code, notes, and snippets.

@ciniml
Created June 1, 2015 01:21
Show Gist options
  • Save ciniml/9c85ce6300c1672d90d7 to your computer and use it in GitHub Desktop.
Save ciniml/9c85ce6300c1672d90d7 to your computer and use it in GitHub Desktop.
static IObservable<T> DeadTime<T>(this IObservable<T> source, TimeSpan deadTime)
{
return Observable.Create<T>(o =>
{
var subscriptions = new CompositeDisposable();
var lastTime = DateTimeOffset.MinValue;
return source
.Timestamp()
.Where(timestamped => timestamped.Timestamp - lastTime > deadTime)
.Do(timestamped =>
{
lastTime = timestamped.Timestamp;
})
.Select(timestamped => timestamped.Value)
.Subscribe(o);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment