【发布时间】:2023-02-21 02:35:35
【问题描述】:
我有一个队列,该队列使用基于 https://caolan.github.io/async/v3/docs.html#queue 的命令并具有异步功能,因为处理需要异步/等待。
this.commandQueue = async.queue(async (task, callback) =>
{
await this.sleep(10); // Long running async stuff
callback(null, data);
}, 1);
任务的结果应通过“数据”发回。
this.commandQueue.push(
{
...command data
}, function (err, data)
{
// called when task finished - callback called
... // data is undefined
});
问题:“数据”未定义。
当我从顶部函数部分删除 async /await 时,它可以工作,但我无法调用我的长时间运行的任务:-(
我不知道如何解决这个问题。有什么提示吗?
【问题讨论】:
-
你应该只是来自
async function的return data。
标签: javascript node.js async-await