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.

how to make async work with async/await

See original GitHub issue
var async = require('async');

var workPool = async.queue(async (task, taskComplete)=>{
  console.log(1, taskComplete);

  async.retry(3, async (retryComplete)=>{

    console.log(2, retryComplete);
    // retryComplete(null, task);

  });
});

workPool.push("test");

I wonder why i got this result:

$ node test.js
1 undefined
2 undefined

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10

github_iconTop GitHub Comments

2reactions
b4dnewzcommented, May 13, 2019

@pawelotto I think for that you can use node promisify util, I didn’t test but since the main callback function signature is compatible I assume it will work.

So the example above will become (without handling error):

import async from "async"
import {promisify} from "util"

const promiseMapLimit = promisify(async.mapLimit)
const results = await promiseMapLimit(files, async file => { // <- no callback!
    const text = await util.promisify(fs.readFile)(dir + file, 'utf8')
    const body = JSON.parse(text) // <- a parse error herre will be caught automatically
    if (!(await checkValidity(body))) {
        throw new Error(`${file} has invalid contents`) // <- this error will also be caught
    }
    return body // <- return a value!
})
1reaction
kazaffcommented, May 15, 2019

Maybe you can try neo-async

Read more comments on GitHub >

github_iconTop Results From Across the Web

async function - JavaScript - MDN Web Docs - Mozilla
Async functions can contain zero or more await expressions. Await expressions make promise-returning functions behave as though they're ...
Read more >
Async/await - The Modern JavaScript Tutorial
The async keyword before a function has two effects: ... The await keyword before a promise makes JavaScript wait until that promise settles,...
Read more >
Async and Await | The Odin Project
await is pretty simple: it tells JavaScript to wait for an asynchronous action to finish before continuing the function. It's like a 'pause...
Read more >
Asynchronous Programming with Async and Await - Visual Basic
A synchronous method returns when its work is complete (step 5), but an async method returns a task value when its work is...
Read more >
using async await and .then together - Stack Overflow
I always use async/await and .catch() instead of using async/await and try/catch to make code compactly. async function asyncTask() { throw ...
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