Unresolving a viewof after it has resolved once

In @mbostock authentication simulator, and unresolved cell is used to hold up dataflow until the user logs in (good idea!)

However, when the user logs out, what should happen? I believe it should return to being unresolved, however, I can’t seem to be able to push a promise back in the viewof _.value, and the last logged in person sticks as a result

Technical repro:

1 Like

There’s not currently a way to do this in the Observable Runtime (as far as I’m aware). When a generator yields a new promise (which happens when you assign a view’s value, or when you assign a mutable), the previously-resolved value is visible to other cells until the new promise resolves. The relevant code is here:

It might be possible to change the Runtime to support this, i.e., to trigger recompute earlier when the promise is yielded rather than when the promise is resolved. Or you could even trigger recompute when waiting for the generator to yield a new value; however that would mean that any generator cell would appear to run continuously rather than only flashing when a new value is yielded.

1 Like

My expectation was I expect it to run twice. Once when a promise is yielded[1], and once when the promise resolves.

[1] though if an already resolved promise was returned then it should run only once, as you would not want downstream cells to doubling computation frequency. Unfortunately, promise state is hard to figure out so that’s a difficult ask :frowning:

=> ergo, I guess the current behaviour is the bestest.

=> I guess the best but not perfect approach to logout is to return undefined.