Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
/index.js
/node_modules
.*.swp
Expand Down
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -588,8 +588,8 @@ all.

__Arguments__

* tasks - An array or object containing functions to run, each function
should return a promise for an optional value.
* tasks - An array, object containing functions to run (each function
should return a promise for an optional value), or an object containing promises that resolve a value
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simpler:
"An array or object containing promises or functions to...."


__Example__

Expand All @@ -603,14 +603,23 @@ async.parallel([
doStuff()
.done()

### an example using an object instead of an array ###
### an example using an object of functions instead of an array ###
async.parallel({
one: -> Q.delay(200).thenResolve(1)
two: -> Q.delay(100).thenResolve(2)
}).then (results) ->
### results is now equals to: {one: 1, two: 2} ###
doStuff()
.done()

### an example using an object of promises instead of an array ###
async.parallel({
one: Q.delay(200).thenResolve(1)
two: Q.delay(100).thenResolve(2)
}).then (results) ->
### results is now equals to: {one: 1, two: 2} ###
doStuff()
.done()
```

---------------------------------------
Expand Down
6 changes: 5 additions & 1 deletion async.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ module.exports = async =
).then(-> results)

parallel: Q.promised (tasks) ->
processArrayOrObject tasks, (arr) -> Q.all arr.map Q.try
processArrayOrObject tasks, (arr) -> Q.all arr.map (task) ->
if task.then
task
else
Q.try task

parallelLimit: Q.promised (tasks, limit) ->
processArrayOrObject tasks, (arr) ->
Expand Down
9 changes: 9 additions & 0 deletions test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,15 @@ describe 'parallel()', ->
/^error1$/
)

it 'accepts an object of promises', ->
obj =
one: Q.delay(125).thenResolve 1
two: Q.delay(200).thenResolve 2
three: Q.delay(50).thenResolve [3,3]

async.parallel(obj).then (results) ->
deepEqual results, one: 1, two: 2, three: [3, 3]

it 'accepts an object', ->
call_order = []
async.parallel(getFunctionsObject call_order).then (results) ->
Expand Down