rxjs icon indicating copy to clipboard operation
rxjs copied to clipboard

fix(debounceTime): handle synchronous schedulers

Open dancras opened this issue 3 years ago • 2 comments

Description:

Using debounceTime(0, queueScheduler) was not emitting any values. scheduler.schedule() emits immediately but logic in debounceTime was expecting it to always return before emitting.

Related issue (if exists):

Fixes https://github.com/ReactiveX/rxjs/issues/6764

dancras avatar Feb 11 '22 15:02 dancras

I see the issue.

I think that a cleaner solution would be to create a Subscription prior to the subscriber.schedule call, and leverage that, something like:

if (!activeTask) {
  subscriber.add(activeTask = new Subscription());
  activeTask.add(scheduler.schedule(emitWhenIdle, dueTime));
}

It's perhaps a little more resource intensive per schedule, but it's certainly less complicated.

Let me know if that works out.

benlesh avatar Mar 10 '22 14:03 benlesh

That is a nice solution. Can confirm it works and cleans up the scheduler.schedule subscription even after the fact in the synchronous case. Learned a little more about Subscriptions, thanks.

dancras avatar Mar 11 '22 12:03 dancras

@dancras Apologies on dropping the ball on landing this one. I think there may be another solution here, and we might still try to get this into the 7.x branch.

benlesh avatar Jan 20 '23 03:01 benlesh

I've added a commit and moved it over here. I'll try to make sure you get credit for the commits, @dancras

https://github.com/ReactiveX/rxjs/pull/7161

benlesh avatar Jan 20 '23 04:01 benlesh