Table of Contents

Method Debounce

Namespace
SodaFlow
Assembly
SodaFlow.dll

Debounce<T, TTime>(Stream<T>, ITimerSystem<TTime>, Func<TTime, TTime>)

Fires the last value after a time with no other value. Each firing moves the alarm out, thus a sequence of firings with no space between them gives one value.

public static Stream<T> Debounce<T, TTime>(this Stream<T> s, ITimerSystem<TTime> timers, Func<TTime, TTime> deadline) where TTime : IComparable<TTime>

Parameters

s Stream<T>

The stream to debounce.

timers ITimerSystem<TTime>

The timer system that gives the clock and the alarms.

deadline Func<TTime, TTime>

The time to fire at, from the time of a firing. For a SystemClockTimerSystem, a quiet time of 300 milliseconds is static now => now.AddMilliseconds(300).

Returns

Stream<T>

A stream that fires the last value of s, one time, after a time with no other value.

Type Parameters

T

The type of the values fired by the stream.

TTime

The type that the timer system uses for a point in time.

Remarks

Each value that a quiet time follows fires one time, and the values before it fire never. A search box is the usual position for this: the text of each keystroke goes in, and one search comes out.

The result is in a transaction of the alarm and never in the transaction of a firing. Thus, a graph that reads the two sees two instants, which is correct: the values are at two times.

This does not cancel work that started. Where each value starts an operation, give a strategy to MapAsync that cancels the operation it replaces, and debounce the input also. The first stops the requests that no code wants, and the second stops the requests before they start.

deadline must give a time after the time that it reads. An earlier time is a time that the clock went by, and it fires at the next transaction.