-
Notifications
You must be signed in to change notification settings - Fork 13
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
Feature request: put multiple awaits into a single Promise.all call #7
Comments
Hi @capaj, Interesting idea, how often do you have to do operations like this? I haven't worked on large projects in nodeJS and can't say that I come across things like that very often in front-end. When I do, it's rare enough to do it by hand. I've toyed with this idea and created an experimental implementation: Rather than selecting statements, you just put the cursor over the I still have concerns though:
You can test the implementation youself by putting this file into the |
I thought code action only shows up when it is provided-so this would only show up when the editor selection has multiple await statements.
I often write some async function and then realize-oh these two awaits don't need to run in sequence. We need to wait for both of them anyway. At this point I am refactoring. There are other
return values would be nice to have-so if I store the result of the promise, that it's still stored in the same variable after refactoring. So for example: ;(async () => {
await moveFile('../node_modules', '../../dist/back-end')
const r2 = await moveFile('../node_modules', '../../dist/back-end')
// select two lines like these, hit the code action
})()
// into:
;(async () => {
const [, r2] = await Promise.all([
moveFile('../node_modules', '../../dist/back-end'),
moveFile('../node_modules', '../../dist/back-end')
])
})() |
Generally, there are two reasons why I'm careful about what actions to implement:
Regarding the subject, here is how I see the implementation now:
Active items:
let foo;
foo = await loadFoo();
let bar = await loadBar();
// =>
let [foo, bar] = await Promise.all([loadFoo(), loadBar()]); // Syntax error here
@capaj, will be glad to hear any thoughts. Cheers! |
Released in v0.11.0. |
I'd love to be able to put many await calls into a Promise.all call via a code action.
So from:
The text was updated successfully, but these errors were encountered: