Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

syncify

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

syncify

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. Syncify does *not use Node Fibers* and **runs on any Javascript environment i

  • 1.1.0
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

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. Syncify does not use Node Fibers and runs on any Javascript environment including the browser.

New: Intro video ( 13 minutes )

Here's a quick example of what Syncify can do for you:


// we have three async functions that go to the server and fetch some data
function getFriendIdsFromServer( id, cb ){ ... }
function getFirstNameFromServer( id, cb ){ ... }
function getLastNameFromServer( id, cb ){ ... }

// we want to create a function that combines them all
function getFriendNamesFromServer( cb ){ ... }

// we don't want to work with callbacks
// so we "syncify" these async functions
// ( we temporarily bring them to the sync world using black magic )
var  getFriendIds = syncify( getFriendIdsFromServer )
var  getFirstName = syncify(  getFirstNameFromServer )
var  getLastName  = syncify(  getLastNameFromServer )

// and we can now combine them using clean, synchronous imperative code
function getFriendNames( id ){
  var names = [];
  var friendIds = getFriendIds( id );
  for ( var i=0; i<friendIds.length; i++ ){
    var id = friendIds[i];
    // look mom. no callbacks!
    names.push( getFirstName( id ) + " " + getLastName( id ) );
  }
  return names;
}

// now that we have our combined function
// we need to bring it back to the async world
// in order to call it
var getFriendNamesFromServer = syncify.revert( getFriendNames )

// voila!
// we can call our combined function
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

FAQs

Package last updated on 23 Dec 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc