RxPY icon indicating copy to clipboard operation
RxPY copied to clipboard

Debounce operator does not ignore values, it queues them with delay

Open teodorkostov-es opened this issue 2 years ago • 3 comments

Describe the bug Debounce operator does not ignore values, it queues them with delay.

To Reproduce

test = rx.interval(0.1).pipe(
    ops.debounce(1.5, scheduler=CurrentThreadScheduler()),
  ).subscribe(print)

Truth be told, I am using a socket as the source. It's providing the data to a Subject in a thread different from the main one. All rx execution happens in that thread.

Expected behavior I would expect values from 2 to around 15 to be dropped.

Additional context Add any other context about the problem here.

  • OS Linux
  • RxPY version 4.0.4
  • Python version 3.10.5

teodorkostov-es avatar Aug 05 '22 10:08 teodorkostov-es

You cannot use the CurrentThreadScheduler here. It cannot schedule blocking work on a single thread (current) without blocking everything else while waiting, so things will not behave as you expect. You need to use a thread-based scheduler e.g TimeoutScheduler, but perhaps ThreadPoolScheduler is a better choice.

dbrattli avatar Aug 08 '22 07:08 dbrattli

@dbrattli, thank you for the help. Unfortunately, these two schedulers do not get the job done. It seems that I have to change something in my threaded app.

When I use these schedulers, the entire pipeline freezes. Could the issue be that I block the main thread with some work while in parallel in another thread, the Rx stream runs with the debounce operator?

teodorkostov-es avatar Aug 09 '22 08:08 teodorkostov-es

It it's not easy to say. Multi-threaded applications can be complex to get right. You will have to experiment and get into the details of this. But you will have to use another scheduler for debounce than the CurrentThreadScheduler.

dbrattli avatar Aug 10 '22 18:08 dbrattli