当另一个方法正在执行时调用流星方法

Call meteor method while another is executing

本文关键字:方法 调用 执行 流星 另一个      更新时间:2023-09-26

我有两个按钮,它们打算充当"开始"answers"停止",当单击时在后端触发方法。如:

{{#if isExecuting}}
  {{>CylonButton method="stop"}}
{{else}}
  {{>CylonButton method="start"}}
{{/if}}

流星方法如下所示。

Meteor.methods({
  start: function (data) {
    Cylon.downloadData(data); // chunks data and downloads it, could take a while
    this.unblock();           // now that it's ready, it can be unblocked.
    Cylon.load();             // do this longer running method.
  },
  stop: function () {
    Cylon.stop();             // stop the method. This should _always_ be available
  }
});

然而,我不能调用stop,直到另一个方法解除阻塞。有办法解决这个问题吗?

this.unblock允许在前一个方法完成之前执行后续方法调用。听起来你想把它移到函数开始时的第一行