-
Notifications
You must be signed in to change notification settings - Fork 337
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
Consistently use async
/await
rather than then
.
#70
Comments
Not necessarily disagreeing but I'm not clear why 'then' (or any task/promise continuation syntax) is considered 'legacy' or not as clear? Is there a typescript style guide documented somewhere we should follow and discuss to come up with the right set of tslint settings? |
I don't see I don't think that a const promises = []
for (const i = 0; i < 10; i++) {
promises.append(makePromise(i).then(...))
}
await Promise.all(promises) You could avoid This issue is more about cases like this: foo(): Promise<string> {
return somePromise.then(result => {
return `Hello, ${result}!`
})
} Compare to: async foo(): Promise<string> {
const result = await somePromise
return `Hello, ${result}!`
} |
I have a preference towards async/await as it seems to cut down on explicit VS Code Extension development supports promises broadly - https://code.visualstudio.com/docs/extensionAPI/patterns-and-principles#_promises |
As I said, I don't necessarily disagree. I checked with our Javascript SDK team regarding your use of the term 'legacy' for 'then' usage and they don't consider it such and in fact raised the same discussion that async/await is preferred but sometimes 'then' is useful. Therefore I don't think a broad 'must not use then()' mandate is appropriate. Our style guide, when we have one, should therefore likely state 'prefer async/await over then()' and show the examples you list as the reason why. Perhaps this issue should mutate into one that creates said style guide in the repo. |
@steveataws Thanks, that sounds good. I worded this issue poorly--I agree that "prefer" is the right terminology. |
Authored-by: Alan Bogusiewicz <alabogus@amazon.com>
In some places, we still use
then
whereasync
/await
would be more clear. We shouldn't have "legacy" code at this early stage of development. We should give the existing codebase a once-over to make sure that we're usingasync
/await
.The text was updated successfully, but these errors were encountered: