我在流星谈话群里找到了答案。相应的代码注释可以在这里找到:
// After making a write (with insert, update, remove), observers are
// notified asynchronously. If you want to receive a callback once all
// of the observer notifications have landed for your write, do the
// writes inside a write fence (set Meteor._CurrentWriteFence to a new
// _WriteFence, and then set a callback on the write fence.)
以防万一你想知道它在实践中的样子——这就是我所做的(在coffeescript中):
Future = __meteor_bootstrap__.require('fibers/future')
...
future = new Future
fence = new Meteor._WriteFence
fence.onAllCommitted ->
fence.retire()
future.ret()
result = Meteor._CurrentWriteFence.withValue fence, ->
# do something that triggers observers
...
return result
fence.arm()
future.wait() # This will return only /after/ all observers fired.
...
这是一个未记录的功能,不能保证长期有效。因此,如果核心团队想要描述一个正式的解决方法,我的问题仍然悬而未决。