“栅栏已经激活——添加写入太晚了" [英] "fence has already activated -- too late to add writes"

查看:39
本文介绍了“栅栏已经激活——添加写入太晚了"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下错误消息是什么意思?

What does the following error message mean?

fence 已经激活——来不及添加写入

fence has already activated -- too late to add writes

以下是获取方法的示例:

Here's an example of how to get it:

环境:

项目创建:

meteor create test
cd test
meteor add coffeescript http
mv test.js test.coffee
meteor

test.coffee:

Records = new Meteor.Collection("records")

if Meteor.is_client
    Meteor.startup ->
        Meteor.call "test"

if Meteor.is_server
    Meteor.methods
        test: ->
            Meteor.http.get "http://www.meteor.com", ->
                Records.insert some:"data"

推荐答案

一旦方法执行完毕,您将无法添加额外的写入.要延迟完成方法,您可以使用 Futures.像这样:

Once the method is done executing you can't add additional writes. To delay completing the methods you can use Futures. Something like this:

Meteor.methods({
  foo: function() {
    var futures = _.map(urls, function(url) {
      var future = new Future();
      var onComplete = future.resolver();

      Meteor.http.get(url, function(error, result) {
        // do whatever you need

        onComplete();
      });

      return future;
    });

    Future.wait(futures);
  }
});

这篇关于“栅栏已经激活——添加写入太晚了"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆