Comparing version 0.0.7 to 0.0.8
@@ -32,13 +32,27 @@ var async = require('async'), | ||
name = args.shift(), | ||
callback = args.pop(), | ||
callback = typeof args[args.length -1] === 'function' ? args.pop() : null, | ||
listeners = emitter.listeners(name); | ||
function handleError (err) { | ||
if (callback) { | ||
callback(err); | ||
} | ||
else { | ||
throw err; | ||
} | ||
} | ||
if (!listeners.length) { | ||
callback(new Error('Tried to invoke `' + name + '` but there were no listeners')); | ||
handleError(new Error('Tried to invoke `' + name + '` but there were no listeners')); | ||
} | ||
else if (listeners.length > 1) { | ||
callback(new Error('Tried to invoke `' + name + '` but there were ' + listeners.length + ' listners')); | ||
handleError(new Error('Tried to invoke `' + name + '` but there were ' + listeners.length + ' listners')); | ||
} | ||
else { | ||
asyncApply(emitter, listeners[0], args, callback); | ||
if (callback) { | ||
asyncApply(emitter, listeners[0], args, callback); | ||
} | ||
else { | ||
return listeners[0].apply(emitter, args); | ||
} | ||
} | ||
@@ -45,0 +59,0 @@ }; |
{ | ||
"name": "eventflow", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "Flow control for your event emitters", | ||
@@ -5,0 +5,0 @@ "main": "eventflow.js", |
@@ -222,3 +222,10 @@ var eventflow = require('../'), | ||
}); | ||
it('should support synchronous invoke', function () { | ||
emitter.on('sync', function () { | ||
return 'isSync'; | ||
}); | ||
assert.equal(emitter.invoke('sync'), 'isSync'); | ||
}); | ||
}); | ||
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
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
14284
293