Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support promises in object #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
support promises in object
  • Loading branch information
parisholley committed Jun 9, 2016
commit 5c97e91c41045caa769918fd32b6c925d9b3b014
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
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