ReactiveX / RxCpp

Reactive Extensions for C++
Apache License 2.0
3.03k stars 390 forks source link

debounce calls on_next prematurely if on_complete is called while an item is being debounced #461

Open javaJake opened 6 years ago

javaJake commented 6 years ago

This is easy to reproduce by editing the test code under the scenario "debounce - no overlap" and given "a source" from:

        auto xs = sc.make_hot_observable({
            on.next(150, 1),
            on.next(210, 2),
            on.next(240, 3),
            on.completed(300)
        });

to:

        auto xs = sc.make_hot_observable({
            on.next(150, 1),
            on.next(210, 2),
            on.next(240, 3),
            on.next(295, 4),
            on.completed(300)
        });

According to my understanding of debounce through RxJava and RxMarbles, this last 4th element should be forgotten.

I'm still trying to figure out a workaround.

kirkshoop commented 6 years ago

Hi, thanks for the report!

workarounds typically involve take..

One suggestion is to use publish() on the source so that it can also be passed to a take_until() added after the debounce().

javaJake commented 6 years ago

I had my eyes on take_until as well. Thank you for the publish suggestion!

javaJake commented 5 years ago

I ended up going with a workaround like this:

.tap(
    [](...){}, // on_next
    [](std::exception_ptr){ // on_error
        // set closed here
    },
    [](){ // on_completed
        // set closed here
    }
)
.debounce(...)
.take_while([](...){
    // check closed here
})

Any update on this bug?