Skip to content

Commit

Permalink
Iterate over boolean values
Browse files Browse the repository at this point in the history
  • Loading branch information
wdavidw committed Feb 16, 2012
1 parent 902a530 commit 9506b0a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/each.coffee
Expand Up @@ -12,7 +12,7 @@ Chained and parallel async iterator in one elegant function
###
module.exports = (elements) ->
type = typeof elements
if elements is null or type is 'undefined' or type is 'number' or type is 'string' or type is 'function'
if elements is null or type is 'undefined' or type is 'number' or type is 'string' or type is 'function' or type is 'boolean'
elements = [elements]
else unless Array.isArray elements
isObject = true
Expand All @@ -24,14 +24,14 @@ module.exports = (elements) ->
parallel = 1
eacher = new Stream
eacher.paused = 0
eacher.readable = true
eacher.pause = ->
eacher.paused++
eacher.resume = ->
eacher.paused--
run()
eacher.destroy = ->
# eacher.destroy = ->
# nothing
eacher.readable = true
eacher.parallel = (mode) ->
# Concurrent
if typeof mode is 'number' then parallel = mode
Expand Down
28 changes: 28 additions & 0 deletions test/ParallelTest.coffee
Expand Up @@ -90,6 +90,34 @@ module.exports =
.on 'end', ->
assert.eql current, 1
next()
'Parallel # boolean': (next) ->
# Current tick
current = 0
each( false )
.parallel( true )
.on 'item', (next, element, index) ->
assert.eql index, 0
current++
assert.eql false, element
next()
.on 'error', (err) ->
assert.ifError err
.on 'end', ->
assert.eql current, 1
# New tick
current = 0
each( true )
.parallel( true )
.on 'item', (next, element, index) ->
assert.eql index, 0
current++
assert.eql true, element
setTimeout next, 100
.on 'error', (err) ->
assert.ifError err
.on 'end', ->
assert.eql current, 1
next()
'Parallel # function': (next) ->
current = 0
source = (c) -> c()
Expand Down

0 comments on commit 9506b0a

Please sign in to comment.