Comparing version 0.0.10 to 0.0.11
'use strict'; | ||
var createPublicMethodName = require('./create-method-name'); | ||
var ServerError = require('./server-error'); | ||
@@ -17,2 +18,3 @@ function Client(transporter, options, cb) { | ||
this._name = options.name; | ||
this._ttl = options.ttl || 1000; | ||
this.methods = {}; | ||
@@ -26,3 +28,3 @@ | ||
} | ||
this.register(methods); | ||
@@ -50,3 +52,3 @@ return cb(null, this); | ||
var cb; | ||
if (!methodName) { | ||
@@ -58,13 +60,29 @@ throw new TypeError('Bograch.on requires a methodName'); | ||
} | ||
while (typeof arguments[++i] !== 'function' && i < arguments.length) { | ||
args.push(arguments[i]); | ||
} | ||
if (typeof arguments[i] === 'function') { | ||
cb = arguments[i]; | ||
} | ||
var publicMethodName = createPublicMethodName(this._name, methodName); | ||
this._transporter.call(publicMethodName, args, cb); | ||
var killed = false; | ||
if (cb) { | ||
var timeoutId = setTimeout(function () { | ||
killed = true; | ||
cb(new ServerError('responseTimeout', | ||
'Method execution exceeded the time limit of `' + this._ttl + '`')); | ||
}.bind(this), this._ttl); | ||
} | ||
this._transporter.call(publicMethodName, args, function () { | ||
if (!killed && cb) { | ||
clearTimeout(timeoutId); | ||
cb.apply({}, arguments); | ||
} | ||
}); | ||
}; | ||
@@ -71,0 +89,0 @@ |
@@ -44,3 +44,8 @@ 'use strict'; | ||
args.push(cb || function () {}); | ||
method.apply({}, args); | ||
try { | ||
method.apply({}, args); | ||
} catch (err) { | ||
cb(err); | ||
} | ||
}); | ||
@@ -47,0 +52,0 @@ }; |
{ | ||
"name": "bograch", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"description": "A communication gateway for NodeJS microservices.", | ||
@@ -5,0 +5,0 @@ "main": "./lib", |
@@ -20,3 +20,3 @@ 'use strict'; | ||
}); | ||
it('should throw an error if no callback function is passed', function () { | ||
@@ -27,3 +27,3 @@ expect(function () { | ||
}); | ||
it('should throw an error if invalid callback function is passed', function () { | ||
@@ -34,3 +34,3 @@ expect(function () { | ||
}); | ||
it('should not throw an exception if the second parameter is a callback function', function () { | ||
@@ -47,3 +47,3 @@ expect(function () { | ||
}); | ||
it('should pass all the arguments', function (done) { | ||
@@ -58,2 +58,22 @@ boServer.on('sum', function (a, b, cb) { | ||
}); | ||
it('should return error if remote method has an uncaught exception', function (done) { | ||
boServer.on('exception', function (cb) { | ||
throw 'foo'; | ||
}); | ||
boClient.call('exception', function (err) { | ||
expect(err).to.be.equal('foo'); | ||
done(); | ||
}); | ||
}); | ||
it('should return error if remote method timed out', function (done) { | ||
boServer.on('timeout', function (cb) { | ||
'I am not calling the callback function. Ever!'; | ||
}); | ||
boClient.call('timeout', function (err) { | ||
expect(err.type).to.be.equal('responseTimeout'); | ||
done(); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 10 instances in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
462
1
55
1
24029
17