我寫的循環,並增加了消息隊列(Azure存儲隊列),像這樣一個小的測試節點的應用程序:處理的消息隊列和使用異步
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
我試圖重寫到處理一百萬個創建使用異步來控制並行運行的工作者函數的數量。這比任何事情都是一次學習練習。
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);
}
我不完全掌握如何將它與異步一起拉。
quiickly skimming這看起來對我好嗎? – Alfred
@Alfred,我將百萬變成了500,進行測試。結果發生的是我看到「完成處理foo」打印到屏幕500次,然後從messageCreated(從azure放置消息的回調)第一個控制檯日誌。 – lucuma