Name: meteor-async
Owner: meteorhacks
Description: Set of async utilities to work with NPM modules inside Meteor
Created: 2014-09-10 15:49:16.0
Updated: 2018-03-21 19:00:34.0
Pushed: 2016-07-08 14:19:44.0
Size: 132
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Set of async utilities to work with NPM modules and other async code blocks.
or add meteorhacks:async
Available in the Server Side only
Meteor APIs are executed synchronously. Most of the NodeJS modules works asynchronously. So we need a way to bride the gap. Async Utilities comes to rescue you.
Async.runSync()
pause the execution until you invoke done()
callback as shown below.
response = Async.runSync(function(done) {
tTimeout(function() {
done(null, 1001);
100);
ole.log(response.result); // 1001
done()
callback takes 2 arguments. error
and the result
object. You can get them as the return value of the Async.runSync()
as shown as response in the above example.
return value is an object and it has 2 fields. error
and result
.
Same as Async.runSync
but deprecated.
Wrap an asynchronous function and allow it to be run inside Meteor without callbacks.
clare a simple async function
tion delayedMessge(delay, message, callback) {
tTimeout(function() {
callback(null, message);
delay);
apping
wrappedDelayedMessage = Async.wrap(delayedMessge);
age
or.methods({
elayedEcho': function(message) {
var response = wrappedDelayedMessage(500, message);
return response;
If the callback has a result, it will be returned from the wrapped function. If there is an error, it will be thrown.
Async.wrap(function)
is very similar toMeteor._wrapAsync
.
Very similar to Async.wrap(function)
,
but this API can be used to wrap an instance method of an object.
github = new GithubApi({
version: "3.0.0"
apping github.user.getFrom
wrappedGetFrom = Async.wrap(github.user, 'getFrom');
Very similar to Async.wrap(object, functionName)
,
but this API can be used to wrap multiple instance methods of an object.
ubApi = Npm.require('github');
github = new GithubApi({
version: "3.0.0"
apping github.user.getFrom and github.user.getEmails
wrappedGithubUser = Async.wrap(github.user, ['getFrom', 'getEmails']);
age
profile = wrappedGithubUser.getFrom({user: 'arunoda'});
emails = wrappedGithubUser.getEmails();