如何创建仅在输入停止一段时间后才输出的信号或流?
How to create a Signal or Stream which only output when the input have been stopped for a period of time?
如何创建仅在输入停止一段时间后才输出的信号或流?
我想要实现的是:
S1 : S - - S S S S - - - - - S S S S - - - -
S2 : - - - - - - - - - S - - - - - - - - S -
我想将 S1 转换为 S2,如果事件已停止 3 -(其中 - 是 x 秒),它只输出最后一个事件。
这是 C# 代码,但你应该可以翻译:
string xs = "S--SSSS-----SSSS----";
IObservable<char> source =
Observable
.Interval(TimeSpan.FromSeconds(1.0))
.Zip(xs.ToCharArray(), (n, c) => c)
.Where(c => c == 'S');
IObservable<char> query =
source
.Select(x =>
Observable
.Timer(TimeSpan.FromSeconds(3.0))
.Select(y => x))
.Switch();
这会在正确的时间生成两个值。
使用方法 throttle:
,它会在发送下一个信号之前等待 x 秒以接收另一个信号。
好的。谷歌搜索后,我找到了我想要的东西。 http://reactivex.io/documentation/operators/debounce.html
如何创建仅在输入停止一段时间后才输出的信号或流?
我想要实现的是:
S1 : S - - S S S S - - - - - S S S S - - - -
S2 : - - - - - - - - - S - - - - - - - - S -
我想将 S1 转换为 S2,如果事件已停止 3 -(其中 - 是 x 秒),它只输出最后一个事件。
这是 C# 代码,但你应该可以翻译:
string xs = "S--SSSS-----SSSS----";
IObservable<char> source =
Observable
.Interval(TimeSpan.FromSeconds(1.0))
.Zip(xs.ToCharArray(), (n, c) => c)
.Where(c => c == 'S');
IObservable<char> query =
source
.Select(x =>
Observable
.Timer(TimeSpan.FromSeconds(3.0))
.Select(y => x))
.Switch();
这会在正确的时间生成两个值。
使用方法 throttle:
,它会在发送下一个信号之前等待 x 秒以接收另一个信号。
好的。谷歌搜索后,我找到了我想要的东西。 http://reactivex.io/documentation/operators/debounce.html