node-modules/ready-callback

Name: ready-callback

Owner: node_modules

Description: Launch server after all async task ready

Created: 2015-02-03 17:20:39.0

Updated: 2018-05-22 03:00:54.0

Pushed: 2017-05-24 18:09:56.0

Homepage:

Size: 55

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

ready-callback

NPM version build status Test coverage David deps npm download

Launch server after all async task ready


Install
m install ready-callback
Usage

Note: ready-callback is using class, so you should use node>=2

koa = require('koa');
ready = require('ready-callback')();
app = koa();
y.mixin(app);

egister a service
done = app.readyCallback('service');
iceLaunch(done);

allback will be fired after all service launched
ready(function() {
p.listen();

Error Handle

If task is called with error, error event will be emit, ready will never be called.

egister a service that will emit error
done = app.readyCallback('service');
iceLaunch(function(err) {
ne(err);


isten error event
on('error', function(err) {
 catch error

Weak Dependency

If you set a task weak dependency, task will be done without emit error.

done = app.readyCallback('service', {isWeakDep: true});
iceLaunch(function(err) {
ne(err);


ill be ready
ready(function() {
p.listen();


on('error', function(err) {
 never be called

You can also set for all ready-callback

ready = require('ready-callback')({isWeakDep: true});
Ready Status

You can get status every callback end.

on('ready_stat', function(data) {
nsole.log(data.id); // id of the ended task
nsole.log(data.remain); // tasks waiting to be ended

Timeout

You can set timeout when a task run a long time.

ready = require('ready-callback')({timeout: 1000});
y.mixin(app);
on('ready_timeout', function(id) {
 this will be called after 1s that `service` task don't complete


done = app.readyCallback('service');
iceLaunch(function() {
 run a long time
ne();

You can also set timeout for every task

y.mixin(app);
on('ready_timeout', function(id) {
 this will be called after 1s that `service` task don't complete


done = app.readyCallback('service1', {timeout: 1000});
iceLaunch(done);
LISENCE

Copyright (c) 2015 popomore. Licensed under the MIT license.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.