-
Couldn't load subscription status.
- Fork 80
don’t expose stale values #333
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
Conversation
src/variable.js
Outdated
| this._name = name; | ||
| } | ||
|
|
||
| ++this._version; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed when you call variable.define (or a wrapper like variable.import) so that the version is incremented synchronously. If we don’t do this, then the version won’t be implemented until the runtime recomputes on the next animation frame, which means we could leak a value that we already know is invalid because the variable was redefined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately I’ve realized that this isn’t sufficient: it’s not enough to just increment the version on the redefined variable; we would also need to increment it on any downstream variable (any variable that depends on this variable). I didn’t want to do that because it involves traversing the dataflow graph, dealing with circular dependencies, etc. But I think we will need to add that here or else it’s still possible to report invalidated values. It shouldn’t have much performance cost because, other than load, variables are rarely redefined, and we should be able to skip the traversal if the variable has never been evaluated.
|
Can you take another look please @duaneatat? I’ve addressed the issue I raised in ba33c34 and I’m feeling good about this now! |
If a variable is redefined before its value resolves, we shouldn’t expose it via module.value. Instead, we should retry to get the variable’s new value.
(It’s possible that this could continue forever if the variable is continuously redefined—e.g., it is both slow asynchronous and downstream from a fast generator—but this is consistent with what you’d in a notebook and hence I feel correct.)
(It’s already the case that observers do not report these invalidated values when fulfilling or rejecting.)