Asynchronous for normal people
JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
examples
README.md
asyn.js
ideas.js
package.json

README.md

Asyn makes Asynchronous code simple.

Basic Structure

asyn
  (console.log)('foo')
  (console.log)('bar')
  .end()

Asynchronous example

  1. Pass asyn as the callback
  2. Results are passed to the end function
asyn
  (fs.readFile)('foo',asyn)  // func 0
  .end(function(asyn){
    /*
     * asyn[0][1] 0 refers to the first funcion
     * while 1 refers to the second argument that
     * is passed to the fs.readFile callback (a buffer)
     */
    console.log(asyn[0][1]);
  })

More Examples

asyn
  (fs.writeFile)('foo','bar',asyn)// func 0
  (fs.readFile)('server.js',asyn)              // func 1
  .end(function(asyn){
    /*
     * Log the second argument (a buffer) of the 2nd func
     */
    console.log(String(asyn[1][1]));
  })

An example calling a functions methods and getting a website.

var array = [0,1,false,true,'','1'];
asyn
  (array,'filter')(Boolean)
  (http.get)({host:'www.google.com',port:80,path:'/'},asyn)
  
  .end(function(asyn){
    console.log(asyn[0]);
    asyn[1][0].on('data',function(chunk){
      console.log('BODY:'+chunk)
    })
  })

Install

npm install asyn