Skip to content

Async/Await example is incorrect #161

@caesarsol

Description

@caesarsol

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions