Skip to content

flatMap with take(1) doesn't unsubscribe from source #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tehsenaus opened this issue Apr 24, 2015 · 3 comments
Closed

flatMap with take(1) doesn't unsubscribe from source #92

tehsenaus opened this issue Apr 24, 2015 · 3 comments
Labels

Comments

@tehsenaus
Copy link

Hi,

I've been hunting memory leaks in my app this week, and I think I've tracked one down to Kefir. It seems that flatMap will unsubscribe once take(1) is done, but then resubscribes again, even though it should now be inactive.

I'm using 1.3.1, not sure if this bug is in v2.

This code will reproduce the problem:

var subCount = 0, unsubCount = 0;
var u = kefir.fromBinder(function (em) {
    subCount++;
    em.emit(1);

    return function () {
        unsubCount++;
    }
})

var s = kefir.fromBinder(function (em) {
    em.emit(1);
}).flatMap(function () {
    return u;
}).take(1);

var data = [], ended = false;
s.onAny(function (ev) {
    if (ev.type === 'value') data.push(ev.value);
    else if ( ev.type === 'end') ended = true;
});

data.should.eql([1]);
ended.should.be.ok;

// subCount = 2, but unsubCount = 1
unsubCount.should.equal(subCount);
@rpominov
Copy link
Member

Thanks! I know this ones are pretty hard to hunt (was fixing couple of similar already), and reproducing code was very helpful.

Is it critical for you to have a fix in v1.x.x?

rpominov added a commit that referenced this issue Apr 26, 2015
* master:
  cleanup repository after release
  2.0.1
  update changelog
  remove not used variables in tests
  fix bug "flatMap with take(1) doesn't unsubscribe" (fix #92)
  minor grammar fixes in bacon-vs-kefir doc
  update bacon-vs-kefir doc
@rpominov
Copy link
Member

Fixed in 2.0.1 and 1.3.2

@rpominov rpominov added the bug label May 5, 2015
@tehsenaus
Copy link
Author

Thanks for the quick fix!

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

No branches or pull requests

2 participants