【发布时间】:2014-11-09 00:23:23
【问题描述】:
我正在尝试模拟一个出版物做大量工作并花费很长时间返回一个光标。
我的发布方法强制休眠(使用未来),但应用始终只显示
加载中...
这是出版物:
Meteor.publish('people', function() {
Future = Npm.require('fibers/future');
var future = new Future();
//simulate long pause
setTimeout(function() {
// UPDATE: coding error here. This line needs to be
// future.return(People.find());
// See the accepted answer for an alternative, too:
// Meteor._sleepForMs(2000);
return People.find();
}, 2000);
//wait for future.return
return future.wait();
});
还有路由器:
Router.configure({
layoutTemplate: 'layout',
loadingTemplate: 'loading'
});
Router.map(function() {
return this.route('home', {
path: '/',
waitOn: function() {
return [Meteor.subscribe('people')];
},
data: function() {
return {
'people': People.find()
};
}
});
});
Router.onBeforeAction('loading');
完整源代码:https://gitlab.com/meonkeys/meteor-simulate-slow-publication
【问题讨论】:
标签: javascript meteor