Skip to content

Instantly share code, notes, and snippets.

@emlynoregan
Created November 21, 2014 02:20
Show Gist options
  • Save emlynoregan/1fdab9096aa08e520190 to your computer and use it in GitHub Desktop.
Save emlynoregan/1fdab9096aa08e520190 to your computer and use it in GitHub Desktop.
Promises using closures
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