-
Notifications
You must be signed in to change notification settings - Fork 353
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
Async functions with variable number of args won't work #180
Comments
It's unclear what the best way to proceed is. Async implementations that accept variable numbers of arguments should previously have been using
I should note that although async function callbacks work much like |
Hey, can i work on this issue. |
@pakya-1909: Thanks for the offer. I think this issue is waiting for @NeilFraser to make a decision about whether he is willing to break backwards compatibility to fix varargs or not. |
How about adding an optional falsely attribute to createAsyncFunction, making it Then in stepCallExpression:
Adds a little overhead for an additional if, but should be backwards compatible with existing code. (Would only break existing code if they were erroneously passing more than one argument to createAsyncFunction.) |
An excellent suggestion. I do wonder if it might be preferable to subsume any new async function support machinery in the work you're doing to support calling interpreted code from native functions, though: see google/CodeCity#172 for what I have in mind. It might be useful to get @NeilFraser to weigh in on this, when he has a moment. |
Sorry, I'm a little confused on what I should be looking at in that link. |
Mainly, as an example, the addition of It basically makes AsyncFunctions obsolete. It means that we wouldn't need to make any changes to the existing |
Consider the following code example:
If executed, the above code throws this error:
The reason seems to be this commit which forces the position of callback to be always the same as the function definition.
I can see the point of the above commit, but would be nice if we could somehow find a workaround for this issue as well.
I wrote a workaround for this issue, which is enough for my existing use-case:
The biggest issue with the above workaround is that it makes every function args size = 101, that is not a very nice and efficient solution.
Instead of the above solution, I would like to propose adding support for async functions that return
Promise
to the interpreter code, another advantage to this is that thePromise
abstraction can also be used to distinguish failure and successful results.If we use
Promise
, we don't need to pass the callback and therefore we can leave the arguments unchanged.I think because the
Promise
object is created outside of the interpreter code, this means the existing code will still work on older browsers.I would love to create a PR with whatever solution you think is best.
The text was updated successfully, but these errors were encountered: