0
有數據插入到Videos集合中,但future.return總是隻返回空對象。如何將post _id返回給客戶端?異步返回插入帖子的_id到Mongo集合
// load future from fibers
var Future = Meteor.npmRequire("fibers/future");
// load fibers
var Fiber = Meteor.npmRequire("fibers");
// load youtubedl
var youtubedl = Meteor.npmRequire('youtube-dl');
Meteor.methods({
'command' : function(line) {
// this method call won't return immediately, it will wait for the
// asynchronous code to finish, so we call unblock to allow this client
this.unblock();
var future = new Future();
\t youtubedl.getInfo(line, function(err, stdout, stderr, videoId) {
\t \t if(stdout)
\t \t Fiber(function() {
\t var videoId = Videos.insert({videoObject: stdout ? stdout : stderr});
\t console.log(videoId);
\t return videoId;
}).run();
\t \t future.return({_id: videoId})
\t });
\t return future.wait();
}
});
BC需要在纖維 – mhlavacka
運行@mhlavacka你不必用戶纖維,'Async.runSync()'將它總是會得到一個錯誤運行它同步示例代碼是一個工作代碼,它將'videoId'返回給客戶端 –