kosich / rxjs-autorun

Re-evaluate an expression whenever Observable in it emits
MIT License
33 stars 2 forks source link

Proposal to wait for at least one value from untracked observable #11

Closed Jopie64 closed 3 years ago

Jopie64 commented 3 years ago

Description

Before I forget, here my proposal for the case that an untracked observable doesn't immediately (synchronously) emit.

In the code there is a place where a decision should still be made:

                                // NOTE: what to do if the silenced value is absent?
                                // should we:
                                // - interrupt computation & w scheduling re-run when first value available
                                // - interrupt computation & w/o scheduling re-run
                                // - continue computation w/ undefined as value of _(o)

I'd propose to go for the first. I think the spec would be something like: an observable is always tracked before it emits its first value. Only then it will be tracked when resolved with $.

Rationale

Consider this scenario:

const r = run(() => _(o1) + $(o2));

If we do the second, this resulting expression will complete without emitting when o1 doesn't immediately emit. If we do the third, then a user should always check untracked observable values for undefined.

In case we do the first, it will wait for a value of o1, then subscribe o2 and start to emit values whenever o2 emits. This IMHO is the best solution.

Let me know what you think. Could you think of a scenario where the first solution would do something inconsistent?

kosich commented 3 years ago

Great catch! Apparently, I didn't think of such case!

AFAIK, this is the current behavior. So, I guess, we'll mark this issue as documentation-related and we gotta keep this in mind with #10

Sounds good?

UPD: had this issue opened before you referenced it in those commits, didn't saw them šŸ˜…

Jopie64 commented 3 years ago

Current behavior is option 4: It waits indefinitely for a value of o1 and doesn't do anything when it receives one :D So I think it needs fixing.

kosich commented 3 years ago

šŸ’©! That needs fixing šŸ˜