parallel-boot-phase
v1.1.3
Published
Parallel boot phase when booting an application.
Downloads
28
Maintainers
Readme
Parallel Boot Phase
Parallel boot phase when booting an application.
Installation
$ npm install parallel-boot-phase
Usage
var parallel = require( 'parallel-boot-phase' );
parallel( ...fcns )
Creates a parallel boot phase based on provided input functions
.
function beep( app, next ) {
// Do something...
next();
}
function boop( app, next ) {
// Do something else...
process.nextTick( next );
}
var phase = parallel( beep, boop );
A function array
is also accepted.
var phase = parallel( [ beep, boop ] );
Notes
- The phase is considered complete when all
functions
have successfully returned. - If a
function
errors or provides anerror
argument to thenext
callback, the phase aborts and causes the boot sequence to fail.
Examples
var express = require( 'express' ),
bootable = require( 'app-boot' ),
parallel = require( 'parallel-boot-phase' );
var phase, boot, app;
// Mock connecting to a database...
function db1( app, config, locals, next ) {
console.log( 'Connecting to database 1...' );
setTimeout( onTimeout, 1000 );
function onTimeout() {
console.log( 'Connected to database 1...' );
locals.db1 = {
'beep': 'boop'
};
next();
}
}
// Mock connecting to a different database...
function db2( app, config, locals, next ) {
console.log( 'Connecting to database 2...' );
setTimeout( onTimeout, 500 );
function onTimeout() {
console.log( 'Connected to database 2...' );
locals.db2 = {
'bop': 'bip'
};
next();
}
}
// Callback invoked once an application boots...
function done( error ) {
if ( error ) {
throw error;
}
console.log( 'Application booted...' );
}
// Create a new application:
app = express();
// Create a boot phase:
phase = parallel( db1, db2 );
// Create a boot function:
boot = bootable( app, {}, {} );
// Register the phase:
boot.phase( phase );
// Boot the application:
boot( done );
To run the example code from the top-level application directory,
$ DEBUG=* node ./examples/index.js
See Also
Tests
Unit
Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:
$ make test
All new feature development should have corresponding unit tests to validate correct functionality.
Test Coverage
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
$ make test-cov
Istanbul creates a ./reports/coverage
directory. To access an HTML version of the report,
$ make view-cov
License
Copyright
Copyright © 2015. Athan Reines.