Meteor:发布和订阅是在客户端和服务器端之间传递值的唯一方式吗?
基本上,当用户登录时,我需要启动一个后台进程。后台进程返回一些敏感数据,服务器端应该进一步处理这些数据,然后将其提供给客户端Meteor:发布和订阅是在客户端和服务器端之间传递值的唯一方式吗?,meteor,Meteor,基本上,当用户登录时,我需要启动一个后台进程。后台进程返回一些敏感数据,服务器端应该进一步处理这些数据,然后将其提供给客户端 这就是Meteor.Publish和Subscribe方法发挥作用的地方吗?还是我需要使用?还有其他方法吗 对于这种情况,您可能希望使用调用而不是发布。这是因为publish函数的用例更多的是决定用户应该看到什么&而不是真正地处理数据(例如,进行web刮取或收集数据)&该过程可能会被阻塞,因此所有客户端可能需要等待该任务完成 我建议你迁移到陨石:通过 您现在可以在访问精彩
这就是Meteor.Publish和Subscribe方法发挥作用的地方吗?还是我需要使用?还有其他方法吗 对于这种情况,您可能希望使用调用而不是发布。这是因为publish函数的用例更多的是决定用户应该看到什么&而不是真正地处理数据(例如,进行web刮取或收集数据)&该过程可能会被阻塞,因此所有客户端可能需要等待该任务完成 我建议你迁移到陨石:通过 您现在可以在访问精彩的社区软件包集合 Ted Blackman的包允许您在用户登录客户端时创建事件 然后,您可以为此创建一个事件: 客户端Js
EventHorizon.fireWhenTrue('loggedIn',function(){
return Meteor.userId() !== null;
});
EventHorizon.on('loggedIn',function(){
Meteor.call("userloggedin", function(err,result) {
console.log("Ready")
if(result) {
//do stuff that you wanted after the task is complete
}
}
});
Meteor.methods({
'userloggedin' : function() {
this.unblock(); //unblocks the thread for long tasks
//Do your stuff to Meteor.user();
return true; //Tell the client the task is done.
}
});
服务器js
EventHorizon.fireWhenTrue('loggedIn',function(){
return Meteor.userId() !== null;
});
EventHorizon.on('loggedIn',function(){
Meteor.call("userloggedin", function(err,result) {
console.log("Ready")
if(result) {
//do stuff that you wanted after the task is complete
}
}
});
Meteor.methods({
'userloggedin' : function() {
this.unblock(); //unblocks the thread for long tasks
//Do your stuff to Meteor.user();
return true; //Tell the client the task is done.
}
});
哈哈,你看透了我的心思!我正要安装eventhorizon,实际上想使用nodejs的EventEmitter,但在meteor中找不到太多关于使用它的信息。