Comments (5)
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?
from aws-toolkit-vscode.
async
/await
is preferred because it allows you to write flat code, rather than adding a level of nesting for each asynchronous call. This makes asynchronous code much easier to read, write, and reason about. The awkward nesting of Task
s/Promise
s/etc. is the motivation for the async
/await
feature in the first place.
I don't see await
vs then
specifically called out in any popular style guide, but any async
/await
guide will explain the advantages. Some examples:
I don't think that a tslint
rule is appropriate, because there are still cases where you might want then
:
const promises = []
for (const i = 0; i < 10; i++) {
promises.append(makePromise(i).then(...))
}
await Promise.all(promises)
You could avoid then
by extracting makePromise(i).then(...)
into a helper function, but using then
here is simpler.
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}!`
}
from aws-toolkit-vscode.
I have a preference towards async/await as it seems to cut down on explicit Promise
usage. In one case, I had wrapped a function in a Promise
constructor, which accidentally ate thrown Errors. I chalk that up to gaining familiarity with the language though too.
VS Code Extension development supports promises broadly - https://code.visualstudio.com/docs/extensionAPI/patterns-and-principles#_promises
from aws-toolkit-vscode.
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.
from aws-toolkit-vscode.
@steveataws Thanks, that sounds good. I worded this issue poorly--I agree that "prefer" is the right terminology.
from aws-toolkit-vscode.
Related Issues (20)
- Add
- unreliable test: getWorkspaceFoldersByPrefixes HOT 4
- "Render state machine graph from CDK application" always fails HOT 2
- No module named 'lambda_function' HOT 2
- Cloudformation template suggestions not working HOT 1
- Can't send to Amazon Q any smart action HOT 1
- Builder Id / SSO page fails ("couldn't complete your request") HOT 6
- Cannot connect to my LearnLab account HOT 3
- Allow Renaming of Files in S3
- CodeWhisperer does not work when the snowflake plugin is activated HOT 2
- Fargate Task with ECS exec Task Role missing under ECS cluster resource
- Runtime for Template Resource undefined or unspecified for dotnet8 function
- sam commands in codecatalyst dev env may fail if they inherit the local setting
- S3 Tree View Not Displaying Bucket Contents with Specific IAM Role Policies
- Authentication Issue with AWS Toolkit in VS Code HOT 2
- VSCode API in extension host uses "Null extension" HOT 2
- upload code to lambda create a new version in aws lambda HOT 6
- bugs
- Debugging .NET 6 Lambda Function Locally Does Not Work
- CodeCatalyst dev environment sessions timing out HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aws-toolkit-vscode.