Syncify.js
In a nutshell, Syncify allows you to temporarily bring asynchronous functions into the synchronous world so you
can focus on solving your problem using clean, imperative code. Here's a quick example of what it looks like:
function getFriendIdsFromServer( id, cb ){ ... }
function getFirstNameFromServer( id, cb ){ ... }
function getLastNameFromServer( id, cb ){ ... }
function getFriendNamesFromServer( cb ){ ... }
var getFriendIds = syncify getFriendIdsFromServer
var getFirstName = syncify getFirstNameFromServer
var getLastName = syncify getLastNameFromServer
function getFriendNames( id, cb ){
var names = [];
var friendIds = getFriendIds( id );
for ( var i=0; i<friendIds.length; i++ ){
var id = friendIds[i];
names.push( getFirstName( id ) + " " + getLastName( id ) );
}
return names;
}
var getFriendNamesFromServer = syncify.async getFriendNames
getFriendNamesFromServer( 78, function( err, names ){
console.log( names.join( ", " ) );
})
Quickstart
Get the code
Using NPM
npm install syncify
Load Javascript on the browser
Take a look at the /build
folder
Caveats
- Functions must be idempotent
- Their arguments must be JSON serializable