-
Notifications
You must be signed in to change notification settings - Fork 7
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
Advantages over yield and synchronous use cases #3
Comments
we should discuss this some as some things become confusing like |
@bmeck not to mention |
As for the question of why we don't just do this with yield, the committee has already decided that the await syntax is desirable enough to pursue because of the status of async/await. This proposal simply aims to make that composition mechanism generic. Although composition functions are flexible enough to be used for any type of decoration, the intention is that they used to compose different scalar asynchronous primitives. My personal opinion is that if you want decoration on any function, we should do that within the context of the decorator proposal. Composition functions are different in that they activate the await syntax, which does not appear to be necessary for many of the examples above. I'm a big fan of decorators and would like to see them used for the use cases you outlined. |
@jhusain wouldn't it be preferable to kill the two birds in one stone? Like you said, these things are powerful enough for it. The syntax they give works and is frankly really nice for decorators - it's clean and unambiguous. Why do we need to make a special case of decorators that don't use the I think this might also make them a lot easier to sell to people who don't really understand the need for asynchronous primitives at all. |
It's definitely an option. I'm not sure how the committee will react to Allowing N modifiers on a function, and exactly what the implications on the parser would be. The most obvious downside would be allowing await in functions where it was not valid. |
I'm not sure I understand, doing What would prevent me from doing
In the current async functions proposal today? It compiles just fine with Babel, it's pointless but it's valid syntactically. |
@jhusain the grammar would get to be in a very bad state, you would need to have the modifiers after the parameter list to avoid confusion like dart does |
@bmeck I agree that this poses a problem and complicates the syntax, I'm not sure if it does so in an ambiguous way - which is why in my original post and examples I used Perhaps someone with more parser experience like @sebmck could shed some light on the complexity (if at all and how much) involved in something like this and why |
@benjamingr right now it works because async is a well known token that is placed in https://github.com/babel/babel/blob/0112c6377914fcb5a1d0287b0bbc5c986d83c6fe/src/babel/transformation/helpers/remap-async-to-generator.js once it becomes a generic identifier things start to get stranger because it requires lookahead. |
@bmeck thanks, that definitely explains it. How would syntax resolution look at this proposal? Does this mean you can only create a compositional function when it's created? (So you can't make a function async from the outside). To be admit, I can't see compelling use cases to make a function "async from the outside" (it also has issues since I posted an issue on the decorators proposal, I think that if decorators are given a hook to |
@benjamingr as it stands async is not done at runtime, it is done at compile time which is partially reflected by the syntax, decorators proposal is done at runtime. The syntax most likely would want to change for await if we had runtime decoration be possible, however
This is all due to compositional/async functions introducing new syntax in the function. We don't allow function decorators to introduce new syntax and probably should not. TL;DR - compositional changes the |
@benjamingr on a different note regarding making async into a decorator by itself, this is possible if we used
is fairly easy to parse / does not require lookahead.
would require lookahead after lexing |
Yes, I see that now. Wouldn't it be possible to require that decorated functions reserve This would also have the same advantage as this proposal of allowing us to use userland implementations and prototype awaiting different things (like cancellable promises for example). That said, in its own |
reserving keywords is pretty cheap for compilers, but I would want to ask people about the goals for language macros (was planned for es8 / es2017) before saying anything about reserving more keywords. |
I think it would be really beneficial in this proposal to explain what this does that
yield
does not enable you to do at the moment. As is, why would you want compositional functions given you can already do this in not-so-bad syntax with yield.I think it might also be very beneficial to expand this proposal (without changing semantics) and explain how this can be used for arbitrary decorators.
Here are some interesting use cases that can be implemented with compositional functions and enjoy this syntax.
I think the fact we can get arbitrary decoration in class declarations and expressions should not be understated here and that there are a lot of interesting use cases to show.
Also, I wonder why not add
async
as a global which makes this proposal completely possible on top of the async/await one and can streamline it.The text was updated successfully, but these errors were encountered: