Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change Promises into async functions #1817

Closed
bartekleon opened this issue Nov 5, 2019 · 1 comment
Closed

change Promises into async functions #1817

bartekleon opened this issue Nov 5, 2019 · 1 comment

Comments

@bartekleon
Copy link
Member

bartekleon commented Nov 5, 2019

We should consider changing Promises to async functions. The 'how it works' would stay the same with the increase of performance (really slight tho) and readability (huge)

@nicojs
Copy link
Member

nicojs commented Nov 7, 2019

Sure, go ahead. Be sure to also take error handling into account.

doWork()
  .then(() => doMoreWork())
  .catch(err => handleError(err))
  .then(() => doEvenMoreWork())

Becomes:

try {
  await doWork();
  await doMoreWork();
} catch(err) {
  await handleError();
}
await doEvenMoreWork();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants