[英]How do I simulate a slow Meteor publication?
我正在嘗試模擬出版物做一堆工作並花費很長時間來返回光標。
我的發布方法有一個強制睡眠(使用未來),但應用程序始終只顯示
這是出版物:
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
最簡單的方法是使用未記錄的Meteor._sleepForMs
函數,如下所示:
Meteor.publish('people', function() {
Meteor._sleepForMs(2000);
return People.find();
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.