caolan / async

Async utilities for node and the browser
http://caolan.github.io/async/
MIT License
28.18k stars 2.41k forks source link

How to get the task result from the callback of push function? #1758

Closed Hazelxfc closed 3 years ago

Hazelxfc commented 3 years ago

What version of async are you using? 3.2 Which environment did the issue occur in (Node/browser/Babel/Typescript version) Node What did you do? Please include a minimal reproducible case illustrating issue. I pass an async function as the execution task and return the result as below and I try to get the this result from the callback of the push function:

  global.q = async.queue( asyncify(async function({filelist}) {  
            const res = await scan(filelist)
            console.log(`res in server :${JSON.stringify(res)}`)
            console.log(`res in server :${res}`)
            return res
        }), 5) 
  global.q.push({filelist},(err, result)=>{ 
      if (err) throw err

    console.log(`result:${JSON.stringify(result)}`)
    response.status(200).send( result) 
    })  

but this doesn't work,the callbaclk didn't called anymore,I am confused by the callback of push function and the call back of the async queue(task,callback) are they same?if true maybe I can't set up a callback to the push function .I also tried this:


let result = await global.q.push({filelist})
    response.status(200).send( result) 

but it didn't work either. Could you kindly look into this?Thanks.

What did you expect to happen?

get the result result from push function of async.queue

What was the actual result? can't get the result of the completed task.

Hazelxfc commented 3 years ago

already fixed,please ignored this issue,thanks.