Created
October 25, 2012 13:48
-
-
Save jgable/3952642 to your computer and use it in GitHub Desktop.
$.when pseudo implementation in CoffeeScript
This file contains hidden or 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
_when = (proms..., cb) -> | |
def = newPromise() | |
promCount = proms.length | |
finishProm = -> | |
promCount-- | |
# May be -1 here... | |
unless promCount > 0 | |
def.resolve() | |
attachTo = (p) -> | |
p.then finishProm, def.reject | |
attachTo prom for prom in proms | |
def.promise() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment