Forked from SachaG/AsynchronousFunctionWithinMeteorMethod.js
Created
June 25, 2013 14:17
-
-
Save jakschu/5858795 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(Meteor.isServer){ | |
Meteor.methods({ | |
myMeteorMethod: function() { | |
// load Future | |
Future = Npm.require('fibers/future'); | |
var myFuture = new Future(); | |
// call the function and store its result | |
SomeAsynchronousFunction("foo", function (error,results){ | |
if(error){ | |
myFuture.throw(error); | |
}else{ | |
myFuture.return(results); | |
} | |
}); | |
return myFuture.wait(); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment