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 - npm Package Compare versions

Comparing version 0.3.2 to 0.4.0

build/syncify.js

6

package.json
{
"name": "syncify",
"version": "0.3.2",
"version": "0.4.0",
"description": "",

@@ -17,3 +17,5 @@ "author": "Aldo Bucchi <aldo.bucchi@gmail.com>",

"chai": "~1.5.0",
"coffee-script": "~1.6.3"
"coffee-script": "~1.6.3",
"browserify": "~2.34.0",
"uglify-js": "~2.4.0"
},

@@ -20,0 +22,0 @@ "repository": "",

@@ -1,10 +0,56 @@

# Syncify
# Syncify.js
Pseudo-Blocking Async Javascript Functions
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:
* Part of the [Radioactive UI Framework](http://github.com/aldonline/radioactive)
* [Reactivity.js](http://github.com/aldonline/reactivity) compatible
```javascript
Installation via NPM
// 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, cb ){
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.async getFriendNames
// voila!
// we can call our combined function
getFriendNamesFromServer( 78, function( err, names ){
console.log( names.join( ", " ) );
})
```
## Quickstart
### Get the code
#### Using NPM
```shell

@@ -14,24 +60,10 @@ npm install syncify

Quickstart
#### Load Javascript on the browser
```coffeescript
syncify = require 'syncify'
Take a look at the `/build` folder
# an async function
get_name_async = ( id, cb ) -> ...
# Caveats
# trasnsform to a blocking/sync function
get_name = syncify get_name_async
* Functions must be idempotent
* Their arguments must be JSON serializable
# do something using the sync function
f1 = ->
# notice that we can call toUpperCase on the value
# because this function now returns sychronously
get_name( 8 ).toUpperCase()
# to execute the above function we need to unblock it
f1 = syncify.async f1
# and the function is async again
f1 (err, res) -> console.log err, res
```
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