sparkpost/tornado/utils.py
raw| 1 | from tornado.concurrent import Future |
| 2 | |
| 3 | |
| 4 | def wrap_future(future, convert): |
| 5 | wrapper = Future() |
| 6 | |
| 7 | def handle_future(future): |
| 8 | try: |
| 9 | wrapper.set_result(convert(future.result())) |
| 10 | except Exception as ex: |
| 11 | wrapper.set_exception(ex) |
| 12 | |
| 13 | future.add_done_callback(handle_future) |
| 14 | return wrapper |