asynchronous - Nested Async Functions - Future return running inside Fibers -
i need run 2 nested async functions , return callback second 1 client. future.return doesn't work inside fibers. how return result client without using collections?
meteor.methods({ 'youtube':function(object) { var youtube = new youtube(); youtube.search(object.song, 1, function(error, result) { if (error) { console.log(error); } else { fiber(function() { var future = new future(); ytdl.getinfo(result.url, function(err, result) { future.return({data: result}); }); return future.wait(); }).run(); } }); });
future should returned in first method scope. , read meteor.bindenvironment
var future = npm.require('fibers/future'); var bound = meteor.bindenvironment(function(callback){ return callback(); }); meteor.methods({ 'youtube':function(object) { var fut = new future(); var youtube = new youtube(); youtube.search(object.song, 1, function (error, result) { bound(function () { if (error) { console.log(error); } else { ytdl.getinfo(result.url, function(err, result) { fut.return({data: result}); }); } }); }); return fut.wait(); } });
Comments
Post a Comment