我有一个队列,我想在每次添加一个值时在该队列上运行一个函数。我正在使用meteor,这是在服务器端btw。
var Queue = [];
var callInQueue; //current api call in the queue. will be the url and a callback
(function QueueLoop () {
if (Queue.length) {
callInQueue = Queue.shift();
Meteor._debug(callInQueue);
}
else { Meteor._debug("nothing in there"); }
} ());
然后我以流星方法将值推入队列
Meteor.methods({
testMethod: function() { Queue.push("hello"); } });