ReactiveX——debounce

only emit an item from an Observable if a particular timespan has passed without it emitting another item

延时发射,延长的这段时间没不能产生新的item

debounce

debounce

The Debounce operator filters out items emitted by the source Observable that are rapidly followed by another emitted item.

template<class... AN>

auto rxcpp::operators::debounce ( AN &&...  an ) -> operator_factory<debounce_tag, AN...>

Return an observable that emits an item if a particular timespan has passed without emitting another item from the source observable.

Template Parameters

Duration the type of the time interval
Coordination the type of the scheduler

Parameters

period the period of time to suppress any emitted items
coordination the scheduler to manage timeout for each event

Returns

Observable that emits an item if a particular timespan has passed without emitting another item from the source observable.

Sample Code

using namespace std::chrono;

auto scheduler = rxcpp::identity_current_thread();

auto start = scheduler.now();

auto period = milliseconds(10);

auto values = rxcpp::observable<>::interval(start, period, scheduler).

    take(4).

    debounce(period);

values.

    subscribe(

        [](long v) { printf("OnNext: %ld\n", v); },

        []() { printf("OnCompleted\n"); });
OnNext: 1
OnNext: 2
OnNext: 4
OnCompleted

猜你喜欢

转载自blog.csdn.net/clarkness/article/details/81199695