Async/Await example is incorrect
See original GitHub issueIn section Async/Await are even cleaner than Promises there are too many await
s, the ones on require()
calls are not necessary.
I believe the code should be:
async function getCleanCodeArticle() {
try {
const response = await require('request-promise').get('https://en.wikipedia.org/wiki/Robert_Cecil_Martin');
await require('fs-promise').writeFile('article.html', response);
console.log('File written');
} catch(err) {
console.error(err);
}
}
Though I would execute the require()
calls in the code outside the function, in this and in all other examples.
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
async/await is the wrong abstraction
What we are trying to do with async/await is to ignore reality and have these async operations appear to be happening synchronously.
Read more >Incorrect value after calling promise async function in js
Try this: onDeviceReady.then(async function () { await howManyRecords(); console.log("after calling function records are: " + records);}.
Read more >Async/await
In actuality, The `await` keyword breaks the synchronous flow and creates a new promise handler from every subsequent statement in the function; ...
Read more >Async/Await - Best Practices in Asynchronous Programming
An approach I like to take is to minimize the code in my asynchronous event handler—for example, have it await an async Task...
Read more >async/await syntax encourages frontend developers to ...
async /await syntax encourages frontend developers to develop incorrect code · It is hard to work with. · Forcing component remounting results in ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’d like to!
two issues solved in one!