Skip to content

Instantly share code, notes, and snippets.

Last active December 19, 2015 13:39
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
A solution to the "staircase problem" posed by node.js's reliance on callbacks. See
# In some util class...
handler = (errText, f) ->
(err, rows) ->
if err?
console.log "#{errText}: #{err}"
# And then:
m = myqlPool()
barHandler = handler "Couldn't get a bar", (bars) ->
console.log("Found a bar!", bar) for bar in bars
fizzHandler = handler "Couldn't get fizzes", (fizzes) ->
foos = [ for fizz in fizzes]
for foo in foos
do (foo) ->
m.query selectBar, [foo], barHandler
m.query getFizzes, fizzHandler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment