Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ready-callback

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ready-callback - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

6

HISTORY.md
2.0.0 / 2017-02-09
==================
* feat: call .ready(err) when callback pass an error (#98)
* chore(package): update mocha to version 2.3.3
1.0.0 / 2015-10-20

@@ -3,0 +9,0 @@ ==================

48

lib/ready.js

@@ -6,3 +6,2 @@ 'use strict';

const ready = require('get-ready');
const extend = require('extend');
const uuid = require('uuid');

@@ -24,12 +23,14 @@ const debug = require('debug')('ready-callback');

* @param {Object} opt
* - {Number} timeout - emit `ready_timeout` when it doesn't finish but reach the timeout, default: 10000ms
* - {Boolean} isWeakDep - whether it's a weak dependency, default: false
* - {Number} [timeout=10000] - emit `ready_timeout` when it doesn't finish but reach the timeout
* - {Boolean} [isWeakDep=false] - whether it's a weak dependency
*/
constructor(opt) {
super();
ready.mixin(this);
this.opt = opt || {};
this.isError = false;
this.cache = new Map();
ready.mixin(this);
setImmediate(function () {
setImmediate(() => {
// fire callback directly when no registered ready callback

@@ -40,3 +41,3 @@ if (this.cache.size === 0) {

}
}.bind(this));
});
}

@@ -53,4 +54,11 @@

if (!obj || this.obj) return null;
// delegate API to object
obj.ready = this.ready.bind(this);
obj.readyCallback = this.readyCallback.bind(this);
// only ready once with error
this.once('error', err => obj.ready(err));
// delegate events
if (obj.emit) {

@@ -62,2 +70,3 @@ this.on('ready_timeout', obj.emit.bind(obj, 'ready_timeout'));

this.obj = obj;
return this;

@@ -74,7 +83,7 @@ }

readyCallback(name, opt) {
const id = uuid.v1();
opt = extend({}, defaults, this.opt, opt);
opt.name = name || id;
const timer = setTimeout(this.emit.bind(this, 'ready_timeout', opt.name), opt.timeout);
const cb = once(function(err) {
opt = Object.assign({}, defaults, this.opt, opt);
const cacheKey = uuid.v1();
opt.name = name || cacheKey;
const timer = setTimeout(() => this.emit('ready_timeout', opt.name), opt.timeout);
const cb = once(err => {
clearTimeout(timer);

@@ -84,7 +93,7 @@ // won't continue to fire after it's error

// fire callback after all register
setImmediate(this.readyDone.bind(this, id, opt, err));
}.bind(this));
debug('[%s] Register task id `%s` with %j', id, opt.name, opt);
setImmediate(() => this.readyDone(cacheKey, opt, err));
});
debug('[%s] Register task id `%s` with %j', cacheKey, opt.name, opt);
cb.id = opt.name;
this.cache.set(id, cb);
this.cache.set(cacheKey, cb);
return cb;

@@ -103,4 +112,7 @@ }

readyDone(id, opt, err) {
if (err && !opt.isWeakDep) {
if (err !== undefined && !opt.isWeakDep) {
this.isError = true;
if (!(err instanceof Error)) {
err = new Error(err);
}
debug('[%s] Throw error task id `%s`, error %s', id, opt.name, err);

@@ -127,3 +139,5 @@ return this.emit('error', err);

module.exports = Ready;
// Use ready-callback with options
module.exports = opt => new Ready(opt);
module.exports.Ready = Ready;

@@ -130,0 +144,0 @@ function getRemain(map) {

{
"name": "ready-callback",
"version": "1.0.0",
"version": "2.0.0",
"description": "Launch server after all async task ready",

@@ -10,3 +10,3 @@ "keywords": [

],
"main": "index.js",
"main": "lib/ready.js",
"files": [

@@ -17,15 +17,15 @@ "index.js",

"dependencies": {
"debug": "~2.2.0",
"extend": "~3.0.0",
"once": "~1.3.2",
"get-ready": "~1.0.0",
"uuid": "~2.0.1"
"debug": "^2.6.0",
"get-ready": "^2.0.0",
"once": "^1.4.0",
"uuid": "^3.0.1"
},
"devDependencies": {
"istanbul": "0",
"eslint": "1",
"koa": "1",
"mocha": "1",
"should": "6",
"spy": "0"
"autod": "^2.7.1",
"egg-bin": "^2.0.2",
"egg-ci": "^1.1.0",
"eslint": "^3.15.0",
"eslint-config-egg": "^3.2.0",
"koa": "^1.2.4",
"spy": "^1.0.0"
},

@@ -40,10 +40,14 @@ "repository": {

"scripts": {
"autod": "autod",
"lint": "eslint .",
"test": "mocha -R spec -t 20000",
"cov": "npm run lint && istanbul cover --report=none node_modules/mocha/bin/_mocha -- -R spec -t 20000 && istanbul report json html",
"autod": "autod -e test/fixtures -f ~ -w"
"test": "npm run lint -- --fix && egg-bin test",
"cov": "egg-bin cov",
"ci": "npm run lint && egg-bin cov"
},
"engines": {
"node": ">=2.0.0"
"node": ">=4.0.0"
},
"ci": {
"version": "4, 6, 7"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc