question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Async/Await example is incorrect

See original GitHub issue

In section Async/Await are even cleaner than Promises there are too many awaits, 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:closed
  • Created 7 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
caesarsolcommented, Jan 23, 2017

I’d like to!

0reactions
caesarsolcommented, Feb 7, 2017

two issues solved in one!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found