Skip to content

Instantly share code, notes, and snippets.

@emlynoregan
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emlynoregan/14512d01ec1b95393653 to your computer and use it in GitHub Desktop.
Save emlynoregan/14512d01ec1b95393653 to your computer and use it in GitHub Desktop.
Simple Distributed Promise
def MyLongRunningFunction(resolve):
try:
# we're in a separate task. Do something long running!
# eventually call resolve(result), with whatever result you made
except Exception, ex:
resolve(ex)
def MyFunctionToRunAfterThat(result):
try:
value = result.value
# we now have the value passed to resolve. Do something with it.
except Exception, ex:
# if resolve() was passed an exception, it'll arrive here when
# we access result.value
logging.exception("failure running long running thing")
PromiseSpace().when(MyLongRunningFunction).then(MyFunctionToRunAfterThat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment