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

add callbacks for async chaining of tasks #1822

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/coffee-script/cake.js

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

16 changes: 12 additions & 4 deletions src/cake.coffee
Expand Up @@ -22,11 +22,19 @@ oparse = null
# Mixin the top-level Cake functions for Cakefiles to use directly.
helpers.extend global,

# Define an asynchronous Cake task with a short name, an optional sentence
# description, and the function to run as the action itself. The function
# takes an additional callback argument to call when it completes.
asyncTask: (name, description, action) ->
[action, description] = [description, action] unless action
tasks[name] = {name, description, action}

# Define a Cake task with a short name, an optional sentence description,
# and the function to run as the action itself.
task: (name, description, action) ->
[action, description] = [description, action] unless action
tasks[name] = {name, description, action}
global.asyncTask name, description, (options, cb) ->
action(options)
cb()

# Define an option that the Cakefile accepts. The parsed options hash,
# containing all of the command-line options passed, will be made available
Expand All @@ -35,9 +43,9 @@ helpers.extend global,
switches.push [letter, flag, description]

# Invoke another task in the current Cakefile.
invoke: (name) ->
invoke: (name, cb) ->
missingTask name unless tasks[name]
tasks[name].action options
tasks[name].action options, cb or (->)

# Run `cake`. Executes all of the tasks you pass, in order. Note that Node's
# asynchrony may cause tasks to execute in a different order than you'd expect.
Expand Down