Permalink
Browse files

Re-throw error when no error or both listeners

  • Loading branch information...
1 parent 233ae99 commit baee495d3b1022633ccb767bc6af4e84877e9ea5 @wdavidw wdavidw committed Feb 9, 2013
Showing with 28 additions and 10 deletions.
  1. +5 −5 lib/each.js
  2. +3 −4 src/each.coffee
  3. +1 −1 test/concurrent.coffee
  4. +19 −0 test/error.coffee
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -101,14 +101,13 @@ module.exports = (elements) ->
else
error = errors[0]
error.errors = []
- lerror = events.error.length
- lboth = events.both.length
- emitError = lerror or (not lerror and not lboth)
- for emit in events.error then emit error if emitError
+ for emit in events.error then emit error if events.error.length
else
args = []
for emit in events.end then emit eacher.done
for emit in events.both then emit error, eacher.done
+ # Not testable but re-throw error if not error or both listeners
+ throw error if error and not events.error.length and not events.both.length
return
return if errors.length isnt 0
while (if parallel is true then (eacher.total * times - eacher.started) > 0 else Math.min( (parallel - eacher.started + eacher.done), (eacher.total * times - eacher.started) ) )
View
@@ -11,7 +11,7 @@ describe 'Concurrent', ->
.on 'item', (element, index, next) ->
index.should.eql current
current++
- element.id.should.eql current,
+ element.id.should.eql current
setTimeout next, 100
.on 'end', ->
current.should.eql 9
View
@@ -170,4 +170,23 @@ describe 'Error', ->
next()
.on 'end', (err) ->
false.should.be.ok
+ it 'catch undefined', (next) ->
+ each( [ 1, 2, 3 ] )
+ .on 'item', (element, index, next) ->
+ Toto.should.throw.an.error
+ .on 'error', (err) ->
+ err.message.should.eql 'Toto is not defined'
+ next()
+ .on 'end', (err) ->
+ false.should.be.ok
+ it 'catch TypeError in concurrent mode', (next) ->
+ each( [ 1, 2, 3 ] )
+ .parallel( 4 )
+ .on 'item', (element, index, next) ->
+ undefined.should.throw.an.error
+ .on 'error', (err) ->
+ err.message.should.eql 'Cannot read property \'should\' of undefined'
+ next()
+ .on 'end', (err) ->
+ false.should.be.ok

0 comments on commit baee495

Please sign in to comment.