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)
- SAM Python Debugger fails to respect breakpoints in VSC when DockerContext is modified to ./
- Amazon Q: unable to sign out, "start URL already exists" HOT 8
- Amazon Q code completion HOT 1
- Translate a piece of code into another code language HOT 3
- Upgrade to vscode-l10n HOT 1
- AWS Toolkit render state machine visual rendering wrong state machine despite showing in the list HOT 5
- Unable to use Amazon Q! HOT 5
- Unable to login to amazon q developer using vs code HOT 6
- Code owner issues HOT 1
- SamLaunchRequestError when running aws-sam debug configuration in VScode HOT 6
- Crashes in the background, often. Usually right after locking the editor. HOT 6
- Sign in to get started doesn't work on Code Editor in SM Studio HOT 1
- Automatically generate commit messages
- Sign in to AWS Toolkit in Visual Studio Code with AWS IAM Identity Center - Start URL not accepted HOT 2
- CLI does not work in codespaces/devcontainers HOT 1
- Issue when using the "Open Dev Environment" command in the CODECATALYST pane
- Jupyter Notebook
- AWS Toolkit VS Code Plugin does not connect to S3 bucket
- @workspace attempts to index python virtual envs (.venv, venv) HOT 1
- Expose a synchronous API to Amazon Q allowing introspecting current session state. HOT 1
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.