meteorhacks/meteor-async

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

Homepage:

Size: 132

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Meteor Async

Set of async utilities to work with NPM modules and other async code blocks.

Installation
or add meteorhacks:async
API

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(function)

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.

Meteor.sync(function)

Same as Async.runSync but deprecated.

Async.wrap(function)

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 to Meteor._wrapAsync.

Async.wrap(object, functionName)

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');
Async.wrap(object, functionNameList)

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();

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.