Ada*_*sen 11 javascript meteor
我正在尝试模拟出版物做一堆工作并花费很长时间来返回光标.
我的发布方法有一个强制睡眠(使用未来),但应用程序始终只显示
这是出版物:
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();
});
Run Code Online (Sandbox Code Playgroud)
和路由器:
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');
Run Code Online (Sandbox Code Playgroud)
完整源代码:https://gitlab.com/meonkeys/meteor-simulate-slow-publication
Dav*_*don 29
最简单的方法是使用未记录的Meteor._sleepForMs函数,如下所示:
Meteor.publish('people', function() {
Meteor._sleepForMs(2000);
return People.find();
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2567 次 |
| 最近记录: |