Last active
August 29, 2015 14:10
-
-
Save emlynoregan/14512d01ec1b95393653 to your computer and use it in GitHub Desktop.
Simple Distributed Promise
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 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