bootevent

0.0.1 • Public • Published

bootevent

Quickly describe async tasks needed to complete bootup. Fluent js interface to acquire resources in lockstep before considering a process to be booted.

install

npm install git://github.com/bewest/bootevent.git

bootevent (ctx, booted) -> {fluent api}

  var bootevent = require('bootevent');

bootevent is a function which returns an api:

It takes a context which is passed around, and optionally takes a booted function to be called when everything is ready.

bootevent.acquire

Takes an async function to run, use this to obtain a resource and assign it to your context.

examples

  var bootevent = require('bootevent');
  return bootevent( ).acquire(function db (ctx, next) {
    console.log('context during acquiring db', ctx, arguments);
    var now = new Date( );
    console.log('starting acquire', arguments);
    setTimeout(function done ( ) {
      ctx.timeout = (new Date( )) - now;
      console.log('simulated later', arguments);
      next( );
    }, 2000)
    ;
 
  })
  .boot(function booted ( ) {
    console.log('START PROCESS', arguments);
  });
  ;
{ ctx: [Function],
  tap: [Function],
  acquire: [Function],
  fail: [Function],
  boot: [Function] }
context during acquiring db {} { '0': {}, '1': [Function] }
starting acquire { '0': {}, '1': [Function] }
simulated later {}
START PROCESS { '0': { timeout: 2001 } }

It's a "fluent" API so you can stack as many acquire calls calss as needed.

Readme

Keywords

none

Package Sidebar

Install

npm i bootevent

Weekly Downloads

308

Version

0.0.1

License

BSD-2-Clause

Last publish

Collaborators

  • bewest