Meteor: async update subscription

I have a subscription that, after calling ready() , performs a number of updates pulling data from other collections:

Meteor.publish('foo', function() {
  this.ready()

  // Several times:
  var extraData = OtherCollection.findOne(...)
  this.changed(..., extraData)
})

How can I run these updates asynchronously? Each update accesses the database, does some computation, and calls changed on the subscription.

I also need to run code after all updates have finished (resynchronize).


Simply save the publish handler and use it later!

var publishHandler;

Meteor.publish('foo', function() {
  publishHandler = this;

  //Do stuff...
});

//Later, retrieve it and do stuff with it
doSomeAsync(Meteor.bindEnvironment(function callback(datum) {
  publishHandler.changed(/* ... */, datum);
}));

//Alternatively with Meteor.setTimeout:
Meteor.setTimeout(function callback() {
  publishHandler.changed(/* ... */, 'someData');
},
10000);

Since it's just in the end a JS object you can also save it in an array or do whatever suits you.
Asynchronously.
Heroically.

链接地址: http://www.djcxy.com/p/87106.html

上一篇: ContentInset在iOS中关闭视图控制器时设置错误

下一篇: 流星:异步更新订阅