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

Generators.observe and Generator.queue throws a TypeError on the console (side effect) #89

Closed
asg017 opened this issue Apr 22, 2019 · 2 comments · Fixed by #162
Closed

Comments

@asg017
Copy link

asg017 commented Apr 22, 2019

(Note: might be a duplicate of #44, but that issue doesnt specifically mention the error)

If you create a Generator with Generators.observe or Generator.queue, and that generator updates in the observable runtime, it throws on error on the console. It doesn't effect the value of the cell, the cell still computes just fine, but it seems the Observable runtime is throwing an error for some reason.

The error I get on the console (in Chrome):

worker.327fbbc92318b…8621ada8bfc37b.js:2 Uncaught (in promise) TypeError: i is not a function
    at Object.return (worker.327fbbc92318b…8621ada8bfc37b.js:2)
    at worker.327fbbc92318b…8621ada8bfc37b.js:2

Notebook displaying the error: https://observablehq.com/d/a28ffdc308b73051

@asg017 asg017 changed the title Generators.observe and Generator.queue throws a TypeError on the console (side effect Generators.observe and Generator.queue throws a TypeError on the console (side effect) Apr 22, 2019
@tmcw
Copy link
Contributor

tmcw commented Apr 22, 2019

🤔 Indeed, where this is failing is around the dispose method - this return is where it expects either null or a dipose() method, but instead it's getting a Promise. Potentially this is a breakage around async generators.

@mbostock
Copy link
Member

Not a bug. But could be improved. Generators.observe doesn’t (currently) let you pass in an async initialize function. If you use an async function, your dispose callback will be a promise instead of a function, hence the type error.

Options:

  1. Generators.observe could ignore the return value of initialize if it’s not a function. This seems like it would fail silently and be harder to debug.

  2. Generators.observe could await the promise to invoke the dispose function. This could mean dispose would never be called (as here because the promise is an infinite loop).

  3. Generators.observe could throw an error immediately if initialize returns something that is not a function. This would make the error more obvious.

I vote for the third option. You’d want to rewrite the generator so that it terminated the infinite loop when the generator is disposed, anyway.

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

Successfully merging a pull request may close this issue.

3 participants