async.queue 排水功能不会触发
async.queue drain function won't fire
我在我的节点 js 应用程序上有一个 async.queue 实现,但 queue.drain 函数最近完全停止触发。
我怀疑这个问题与我在任务函数中的 await 语句有关,但我也能够使用 async docs
上的示例重现该问题
const async = require('async')
var q = async.queue(function(task, callback) {
console.log('hello ' + task.name);
callback();
}, 1);
q.drain(function() {
console.log('all items have been processed');
});
q.push({name: 'bar'});
q.push({name: 'foo'}, function(err) {
console.log('finished processing foo');
});
这将在我的控制台上输出以下内容,但不会输出 drain 语句。那么是不是我遗漏了什么?
hello bar
hello foo
finished processing foo
有趣的是,将 drain 函数转换为箭头函数解决了这个问题。
q.drain = function () {
console.log('all items have been processed');
}
q.drain(() => {
console.log('all items have been processed');
}
我在我的节点 js 应用程序上有一个 async.queue 实现,但 queue.drain 函数最近完全停止触发。
我怀疑这个问题与我在任务函数中的 await 语句有关,但我也能够使用 async docs
上的示例重现该问题const async = require('async')
var q = async.queue(function(task, callback) {
console.log('hello ' + task.name);
callback();
}, 1);
q.drain(function() {
console.log('all items have been processed');
});
q.push({name: 'bar'});
q.push({name: 'foo'}, function(err) {
console.log('finished processing foo');
});
这将在我的控制台上输出以下内容,但不会输出 drain 语句。那么是不是我遗漏了什么?
hello bar
hello foo
finished processing foo
有趣的是,将 drain 函数转换为箭头函数解决了这个问题。
q.drain = function () {
console.log('all items have been processed');
}
q.drain(() => {
console.log('all items have been processed');
}