Skip to content
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

MemoryStream doesn't immediately return the cached value to a new subscriber #240

Open
tomazy opened this issue Feb 27, 2018 · 1 comment

Comments

@tomazy
Copy link

tomazy commented Feb 27, 2018

I'm trying to use xstream streams as a store in a React project and I'm quite happy with it. The only issue I have is with MemoryStreams not working as I would expect with regards to caching.

I'm not sure if this is a bug or per design.

When I subscribe to a memory stream as the first subscriber (for the first time) the chain of computation starts and I eventually get a value, that the stream will cache for all the subsequent subscribers.

Now, when all the subscribers unsubscribe, the stream knows the latest computed value.

But when I subscribe again to it, it will start the chain of computation again, even though it already has the value for me.

Is this expected behaviour?

I see in the code that in MemoryStream#_stopNow method you explicitly tell the stream that the value is stale via _has flag:

this._has = false;

Could anyone explain the rationale behind it please?

EDIT: Here is a demo of the problem: https://glitch.com/edit/#!/polar-cry

@wclr
Copy link
Contributor

wclr commented May 1, 2019

Now, when all the subscribers unsubscribe, the stream knows the latest computed value.

I believe it is expected. After there no subscriptions anymore a stream actually completes (and "forgets" everything, actually it dies). If you subscribe again it will resurrect, but will not give you the latest value from its past life.

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

No branches or pull requests

2 participants