Skip to content

Compose multiple async functions together to operate on a result.

Notifications You must be signed in to change notification settings

timoxley/async-compose

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

async-compose

Compose a series of async functions together to manipulate an object.

Similar to an async reduce function, but each iteration pops a
function from a stack of transformations.

Installation

$ component install timoxley/async-compose

Example

var compose = require('async-compose')
var request = require('visionmedia-superagent')

function getInfo(user, next) {
	request
	.get('https://api.github.com/users/' + user.name)
	.end(function(res) {
		user.hireable = res.body.hireable
		user.avatar_url = res.body.avatar_url
		next(null, user)
	})
}

function getOrgs(user, next) {
	request
	.get('https://api.github.com/users/'+user.name+'/orgs')
	.end(function(res) {
		user.orgs = res.body
		next(null, user)
	})
}

var loadInfo = compose([getInfo, getOrgs])

loadInfo({name: 'timoxley'}, function(err, user) {
	console.log('User details: %o', user)
})

License

MIT

About

Compose multiple async functions together to operate on a result.

Resources

Stars

Watchers

Forks

Packages

No packages published