(count, callback, err_cb)
| 6283 | module.exports = after |
| 6284 | |
| 6285 | function after(count, callback, err_cb) { |
| 6286 | var bail = false |
| 6287 | err_cb = err_cb || noop |
| 6288 | proxy.count = count |
| 6289 | |
| 6290 | return (count === 0) ? callback() : proxy |
| 6291 | |
| 6292 | function proxy(err, result) { |
| 6293 | if (proxy.count <= 0) { |
| 6294 | throw new Error('after called too many times') |
| 6295 | } |
| 6296 | --proxy.count |
| 6297 | |
| 6298 | // after first error, rest are passed to err_cb |
| 6299 | if (err) { |
| 6300 | bail = true |
| 6301 | callback(err) |
| 6302 | // future error callbacks will go to error handler |
| 6303 | callback = err_cb |
| 6304 | } else if (proxy.count === 0 && !bail) { |
| 6305 | callback(null, result) |
| 6306 | } |
| 6307 | } |
| 6308 | } |
| 6309 | |
| 6310 | function noop() {} |
| 6311 |
no test coverage detected