【发布时间】:2023-03-24 09:22:01
【问题描述】:
我编写了一个小型测试节点应用程序,它循环并将消息添加到队列(天蓝色存储队列),如下所示:
var queueService = azure.createQueueService();
var queueName = 'taskqueue';
// other stuff like check if created
// loop called after queue is confirmed
for (i=0;i<1000;i++){
queueService.createMessage(queueName, "Hello world!", null, messageCreated);
}
// messageCreated does nothing at the moment, just logs to console
我正在尝试重写它来处理说 100 万个使用异步来控制并行运行的工作函数的数量的创建。这比什么都重要。
https://github.com/caolan/async#queue
这是异步队列的基本设置,我对需要更改的内容有点茫然。我认为以下方法行不通:
var q = async.queue(function (task, callback) {
queueService.createMessage(queueName, task.msg, null, messageCreated);
callback();
}, 100);
// assign a callback. Called when all the queues have been processed
q.drain = function() {
console.log('all items have been processed');
}
// add some items to the queue
for(i=0;i<1000000;i++) {
q.push({msg: 'Hello World'}, function (err) {
console.log('finished processing foo');
});
console.log('pushing: ' + i);
}
我不太明白如何将它们与异步结合在一起。
【问题讨论】:
-
快速浏览一下我觉得没问题..?
-
@Alfred,我将百万改为 500 进行测试。最终发生的事情是我看到“完成处理 foo”打印到屏幕 500 次,然后是 messageCreated 的第一个控制台日志(来自 azure put 消息的回调)..
标签: node.js asynchronous azure azure-storage