Skip to content

Instantly share code, notes, and snippets.

@technoweenie
Created August 26, 2010 22:26
Show Gist options
  • Save technoweenie/552381 to your computer and use it in GitHub Desktop.
Save technoweenie/552381 to your computer and use it in GitHub Desktop.
Step.js ported to coffeescript, with fewer features
# Step(
# () -> redis.select 15, @
# () -> redis.flushdb @
# () -> redis.rpush 'fakelist', '1', @
# () -> redis.rpush 'fakelist', '2', @
# () -> redis.rpush 'fakelist', '3', @
# () -> redis.lrange 'fakelist', 0, 1, @
# (err, arr) ->
# console.log arr.length
# console.log arr[0].toString()
# console.log arr[1].toString()
# @()
# () -> redis.close()
# )
Step = (queue...) ->
context = (args...) ->
if fn = queue.shift()
try
run fn, args
catch err
run fn, [err]
run = (fn, args) ->
fn.apply context, args
context()
# If the first arg exists, log it to the console, and then pass the
# rest of the args to the next step.
Step.errCheck = (err, args...) ->
console.log err.stack if err
@(args...)
module.exports = Step
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment