【问题标题】:Meteor.js server method queueMeteor.js 服务器方法队列
【发布时间】:2016-03-01 00:02:50
【问题描述】:

我在 Meteor 中有一个方法需要一些时间来执行,并且这个方法被调用了很多次,参数不同。

但是客户端可以在数据仍在加载时更改参数,所以我希望服务器能够以某种方式清除方法队列。有可能吗

仅举个例子:

服务器:

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 连接,如果它仍然执行,它会占用大量服务器不需要的请求。

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

// 彼得

【问题讨论】:

    标签: meteor methods fibers


    【解决方案1】:

    【讨论】:

    • 是控制这个的唯一方法,首先将我所有的方法调用添加到集合中吗?只是认为这是一种奇怪的方法。此外,我不希望作业堆积...我希望每个客户端都有自己的堆栈,但只想能够取消堆栈中所有不需要的请求。
    猜你喜欢
    • 2015-12-05
    • 1970-01-01
    • 1970-01-01
    • 2018-08-26
    • 2015-04-29
    • 1970-01-01
    • 2014-07-02
    • 2014-02-23
    • 2014-07-26
    相关资源
    最近更新 更多