2016-03-01 85 views
0

我在Meteor有一個方法需要一點時間來執行,並且這個方法被不同的參數調用了很多次。Meteor.js服務器方法隊列

但客戶端可以在數據仍在加載時更改參數,所以我希望服務器能夠以某種方式清除方法隊列。這是可能的

所以只是例子:

服務器:

Meteor.methods({ 
    'getLongTimeExecutedData': function (settings, reset) { 
    let self = this; 
    if(reset) { 
     // How to reset my entire queue here. 
    } 
    Meteor._sleepForMs(1000); 
    let myData = { settings: settings, timestamp: new Date() }; 
    return myData; 
    } 
}); 

客戶:

Meteor.call('getLongTimeExecutedData', { param1: 'test' , param2: 1 }, false); 
Meteor.call('getLongTimeExecutedData', { param1: 'test' , param2: 2 }, false); 
Meteor.call('getLongTimeExecutedData', { param1: 'test' , param2: 3 }, false); 
... 
// Reset queue on server with true here 
Meteor.call('getLongTimeExecutedData', { param1: 'test2' , param2: 1 }, true); 
Meteor.call('getLongTimeExecutedData', { param1: 'test2' , param2: 2 }, false); 
Meteor.call('getLongTimeExecutedData', { param1: 'test2' , param2: 3 }, false); 
... 

我不想使用this.unblock(),這是因爲方法正在使用MS SQL連接,如果它仍然執行,它會佔用大量不需要的服務器請求。

希望有人有一些想法? :)

//彼得

回答