Permalink
Browse files

safe throws if it does not have a callback

  • Loading branch information...
1 parent 414f604 commit 40be8faa960f6af668e4a590040588c9f1e3ff75 @dominictarr committed Sep 9, 2011
Showing with 10 additions and 286 deletions.
  1. +9 −2 async.js
  2. +0 −283 npm-debug.log
  3. +1 −1 package.json
View
@@ -72,11 +72,18 @@ function tryCatchPass (_try,_catch,_pass) {
exports.safe = safe
+function fName (funx) {
+ return '[' + (funx.name || funx.toString().slice(0,100) + '...') + ']'
+}
+
function safe (funx) {
- var err = new Error((funx.name || funx.toString().slice(0,100) + '...') + ' called more than once')
+ var err = new Error( fName(funx) + ' called more than once')
return function () {
var _callback = arguments[arguments.length - 1]
- , n = 0
+ if('function' !== typeof _callback)
+ (function (){ throw new Error('expected ' + _callback + 'to be a function') })()
+
+ var n = 0
, callback =
arguments[arguments.length - 1] = function () {
var args = [].slice.call(arguments)
Oops, something went wrong.

0 comments on commit 40be8fa

Please sign in to comment.