Created
November 21, 2014 02:20
-
-
Save emlynoregan/1fdab9096aa08e520190 to your computer and use it in GitHub Desktop.
Promises using closures
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
def DoABigThing(aListOfNumbers, callWhenSucceededF, callWhenFailedF): | |
def DoTheThing(resolve, initialValue): | |
theSum = sum(aListOfNumbers) + initialValue | |
theSum += # also get some stuff from a webservice or datastore or something else slow? | |
resolve(theSum) | |
def DoneTheThing(result): | |
try: | |
callWhenSucceededF(result.value) | |
except Exception, ex: | |
callWhenFailedF(ex) | |
PromiseSpace().when(DoTheThing, 47).then(DoneTheThing) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment