A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/dotnet/reactive/issues/395 below:

Implement a real throttle (not debounce, like the existing throttle) · Issue #395 · dotnet/reactive · GitHub

Currently there is no operator to ignore elements from an observable sequence that follow a non-ignored element within a specified relative time duration. This is what would normally be called Throttle, while the existing Throtte operator is really a debounce operator (see e.g. The Difference Between Throttling and Debouncing).

Here is a sample implementation of the "real" throttle operator both with and without scheduler:

public static IObservable<TSource> AtMostOnceEvery<TSource>(
    this IObservable<TSource> source,
    TimeSpan dueTime)
{
    IObservable<TSource> delay = Observable.Empty<TSource>().Delay(dueTime);
    return source.Take(1).Concat(delay).Repeat();
}

public static IObservable<TSource> AtMostOnceEvery<TSource>(
    this IObservable<TSource> source,
    TimeSpan dueTime,
    IScheduler scheduler)
{
    IObservable<TSource> delay = Observable.Empty<TSource>().Delay(dueTime, scheduler);
    return source.Take(1).Concat(delay).Repeat();
}

reduckted, malj, rgwood, anslmorvan, RafiHenig and 11 more


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4