要点:https://gist.github.com/FA-ViPer/39d6529edf8be6d376a9#file-gistfile1-txt
我不确定如何从下面的代码中删除setTimeout函数,并且仍然可以将我的track变量插入到“Carousel”集合中。
asyncJob: function(id) {
Future = Meteor.npmRequire('fibers/future');
Fiber = Meteor.npmRequire('fibers');
// Set up a future
var fut = new Future();
var tracks;
//ueses a promise to get the tracks
musicApi.getMySavedTracks()
.then(function(data) {
tracks = data.items;
console.log(Carousel.findOne({}));
}, function(err) {
console.error(err);
return "failure";
});
// I do not know how to rework the portion below to not have the setTimeout
//the end goal is to replace the console.log with Carousel.insert({track});
setTimeout(function() {
Fiber(function() {console.log(Carousel.findOne({}), tracks.length);}).run();
// Return the results
fut['return'](tracks);
}, 3 * 1000);
// Wait for async to finish before returning the result
return fut.wait();
}