Join async callbacks with ease. CPS1-compliant.

Usage no npm install needed!

<script type="module">
  import joinback from '';



Join multiple async callbacks using joinbacks and handle results with an appealing, unobtrusive API.



var fs = require( 'fs' );
var joinback = require( 'joinback' );

// Create a joinback
var jb = joinback();

// Call async functions with callbacks generated from jb
fs.readFile( 'big.jpg', jb() );
fs.stats( 'big.jpg', jb() );

// Register function to be called when all callbacks of 'jb' are done.
// Results are passed as arguments in order.
// Only the first error is passed, if any.
jb( function( err, file, stats ) {

    // ...

} );

// Results may also be collected in an array
var collect = joinback( true );

fs.readFile( 'a.txt', collect() );
fs.readFile( 'b.txt', collect() );
fs.readFile( 'c.txt', collect() );

collect( function( err, files ) {

    // files is an array of file buffers

} );


var joinback = require( 'joinback' )

Require joinback factory.

var jb = joinback( opt asArray )

Creates a joinback, a function that generates callbacks for async functions, and finally expects a callback to handle the results passed to the generated callbacks.

The results are stored and passed as arguments, or as an array if asArray is truthy.


Creates a callback to be used in an async function.

jb( callback )

Registers the final callback to be called when all callbacks of jb are done or an error occured. In case of an error, only the first error is passed to the callback and any results are discarded. The callback should be CPS1, i.e. function( err, result1, result2, ... ) { ... }.

Do this only after creating all callbacks with jb(), otherwise the final callback may be called too early.

All generated functions or callbacks are CPS1-compliant, and should be used with CPS1 async functions.