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

Node.js Async Function Best Practices #6

gergelyke opened this Issue Oct 23, 2017 · 6 comments


5 participants

gergelyke commented Oct 23, 2017

No description provided.

@gergelyke gergelyke added the comments label Oct 23, 2017


This comment has been minimized.


gergelyke commented Oct 25, 2017

@ksmithut thanks, fixed it!


This comment has been minimized.

xkizer commented Oct 26, 2017

async function main () {
  const [user, product] = await Promise.all([
  await makePurchase(user, product)

can also be written as

async function main () {
  const user = Users.fetch(userId)
  const product = Products.fetch(productId)
  await makePurchase(await user, await product)

This comment has been minimized.

slavaGanzin commented Oct 26, 2017

You do await + callbacks. "Best practices"? For real?


This comment has been minimized.

ksmithut commented Oct 26, 2017

@slavaGanzin If you're referring to the express example, express uses callbacks exclusively, no way around it (ATM). So for express, yes, if that's what you're referring to.


This comment has been minimized.

slavaGanzin commented Oct 30, 2017

@ksmithut No, I'm talking about last example from this article:

const util = require('util')
const async = require('async')
const numbers = [
  1, 2, 3, 4, 5
mapLimitAsync = util.promisify(async.mapLimit)
async function main () {
  return await mapLimitAsync(numbers, 2, (number, done) => {
    setTimeout(function () {
      done(null, number * 2)
    }, 100)

Callbacks, promisified callbacks, await. This code is utter mess


This comment has been minimized.

phelma commented Nov 1, 2017

The @sindresorhus promise-fun repo has a bunch of good promise helper modules, as an alternative to using the async module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment