def promise_then_job(job, promise, prev_promise_returned):
"""
Toil job that runs a promise created with a then handler instead of an
executor.
Takes the promise and the (resolve value, reject value) pair from the
previous promise.
Returns the promise's success result and error, as a pair.
"""
then_handler = dill.loads(promise.then_dill)
resolved, rejected = prev_promise_returned
if rejected is None:
# Actually run this child promise
try:
# Get the result from the then handler and resolve with it
result = then_handler(resolved)
promise.handle_resolve(job, result)
except Exception as e:
# Reject with an error if there is one
Logger.error("".join(traceback.format_exception(*sys.exc_info())))
promise.handle_reject(job, e)
else:
# Parent promise rejected so we should not run
# Bubble up the error
promise.handle_reject(job, rejected)
return (promise.result, promise.err)
评论列表
文章目录