Skip to content

Commit

Permalink
Async arguments manipulation
Browse files Browse the repository at this point in the history
  • Loading branch information
galedric committed Jun 23, 2012
1 parent 89db3eb commit 0b33bbe
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
22 changes: 14 additions & 8 deletions flowing.coffee
Expand Up @@ -205,9 +205,9 @@ class StepDelegate
return

# Execute functions in parallel
parallel: ->
parallel: (p_opt) ->
@_async = true
return @_parallel_callback @_p_args, @_p_idx++
return @_parallel_callback @_p_args, @_p_idx++, p_opt

# Allocate a slot in arguments for parallel execution
group: ->
Expand All @@ -217,10 +217,10 @@ class StepDelegate
local_idx = 0

# Group-callback generator
return => @_parallel_callback local_args, local_idx++
return (p_opt) => @_parallel_callback local_args, local_idx++, p_opt

# Generate parallel callback
_parallel_callback: (arr, idx) ->
_parallel_callback: (arr, idx, p_opt) ->
@_p_count++

# Init result value
Expand All @@ -233,9 +233,15 @@ class StepDelegate
if e
@error e
else
if args.length > 0
# Extract from array if only one value
arr[idx] = if args.length == 1 then args[0] else args
if typeof p_opt == "function"
# Use the given p_opt filter
arr[idx] = p_opt args...
else if typeof p_opt == "number"
# Take only the p_opt-th argument
arr[idx] = args[p_opt]
else if args.length > 0
# Extract from array if only one value (only if p_opt is false)
arr[idx] = if args.length == 1 && p_opt then args[0] else args
@_parallel_done()

return
Expand Down Expand Up @@ -366,5 +372,5 @@ flowing.async = (step) -> tag step, "async"
flowing.delayed = (step) -> tag step, "delay"

# Exports
flowing.version = "0.5.5"
flowing.version = "0.5.6"
module.exports = flowing
20 changes: 12 additions & 8 deletions flowing.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -3,7 +3,7 @@
"description": "A Flow.js / Step derivated multi-step asynchronous logic library",
"author": "Copperflake",

"version": "0.5.5",
"version": "0.5.6",
"licenses": [{
"type": "MIT",
"url": "http://github.com/copperflake/flowing/raw/master/LICENSE"
Expand Down

0 comments on commit 0b33bbe

Please sign in to comment.