Skip to content

Conversation

ppoliani
Copy link
Contributor

@ppoliani ppoliani commented Aug 10, 2017

When disposing a debounce stream we also need to dispose the source disposable

Summary

I was trying to use debounce in the following scenario

combine(...streams$)
    .debounce(1000)
    .chain(chainStream)
    .subscribe(observer);

But I soon realized that when I tried to dispose the above stream, it would ignore disposing the stream (source stream) that comes before the debounce.

Todo

  • Unit tests for new or changed APIs and/or functionality
  • Documentation, including examples

When disposing a debounce stream we also need to dispose the source disposable
@@ -110,6 +110,7 @@ DebounceSink.prototype.error = function (t, x) {

DebounceSink.prototype.dispose = function () {
this._clearTimer()
this.disposable.dispose()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yikes. Good catch, @ppoliani. This just needs a return, return this.disposable.dispose() since disposables typically form a promise chain in the current version of most.js.

@briancavalier
Copy link
Member

It'd be great to add a regression test for this as well. There's a FakeDisposeSource in test/helper that is helpful in writing tests to verify disposal, and here's an example of using it (there are other examples in the test folder as well).

@briancavalier
Copy link
Member

Looking good @ppoliani. Thanks for adding the test. I was porting your fix to @most/core in mostjs/core#107, and I noticed that there's actually another bug in the DebounceSink constructor. It's not necessary to use dispose.all (or disposeBoth in @most/core), and the source disposable can just be assigned directly to this.disposable.

Take a look at mostjs/core#107 and see what you think. If that seems right, then you can do the same here.

@ppoliani
Copy link
Contributor Author

@briancavalier The change makes sense 😄

I'll include it here, as well.

@briancavalier briancavalier merged commit a8322e9 into cujojs:master Aug 11, 2017
@briancavalier
Copy link
Member

Awesome, thank you, @ppoliani. We'll get this out in the next release soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants