0
在Node.js的模塊(自定義隊列)我的工作, 我現在用的是queue module,我需要推入其數組「作業」帶有參數的多個函數(估計時間爲int) 當我啓動隊列時,出現一個錯誤,指出作業不是函數。 我想我明白了爲什麼,這是因爲當我按下它時,會執行「process」函數。但是我需要稍後用參數執行這個過程。
我的代碼:
module.exports = Queue
var process = require("../test/processjob")
var q = require("queue");
function Queue(options) {
if (!(this instanceof Queue)) {
return new Queue(options);
}
options = options || {}
this.queue = q();
/*
handling other options
*/
}
Queue.prototype.processJob = function() {
for (var i = 0, len = this.tasks.length; i < len; i++) {
this.queue.push(process.process(this.tasks[i].estimated_time));// <== push here
}
this.queue.start(); //<== exception here
}
非常感謝,爲我的英文不好對不起。
所以,我試過你的解決方案,它似乎部分工作,異常消失了,但是當一個隊列開始([queue.start()](https://www.npmjs.com/package/隊列#qstartcb))這些作業似乎沒有處理。 –
好吧,讓我看看你提到的隊列庫,看看你的實現中是否有什麼問題 – linasmnew
試試我更新的答案 – linasmnew