Last active
March 3, 2018 23:42
-
-
Save sbimikesmullin/88b6548c76fa3232e7e8 to your computer and use it in GitHub Desktop.
Q: oversimplified asynchronous flow control
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
r = ( | |
((next)-> | |
execute "#{if o?.sudo then 'sudo ' else ''}mkdir #{if o?.recursive then '-p ' else ''}#{if o?.chmod then '-m'+o.chmod+' ' else ''}#{name}", next | |
return | |
)(->((next)-> | |
#return next() unless o?.user or o?.group | |
execute "#{if o?.sudo then 'sudo ' else ''}chown #{o?.user}:#{o?.group} #{name}", next | |
return | |
)(cb)) | |
) | |
# will execute top to bottom and then call cb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# oversimplified asynchronous flow control | |
module.exports = new: -> | |
Q = [] | |
Q.then = (fn, args...) -> Q.push(-> args.push Q.next; fn.apply null, args); @ | |
Q.next = (err) -> Q.splice 0, Q.length-1 if err; Q.shift()?.apply null, arguments | |
Q.finally = (fn, args...) -> Q.push(-> fn.apply null, args); Q.next() | |
Q |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment