MCPcopy Create free account
hub / github.com/EasyIME/PIME / chain_future

Function chain_future

python/python3/tornado/concurrent.py:140–172  ·  view source on GitHub ↗

Chain two futures together so that when one completes, so does the other. The result (success or failure) of ``a`` will be copied to ``b``, unless ``b`` has already been completed or cancelled by the time ``a`` finishes. .. versionchanged:: 5.0 Now accepts both Tornado/asyncio

(a: "Future[_T]", b: "Future[_T]")

Source from the content-addressed store, hash-verified

138
139
140def chain_future(a: "Future[_T]", b: "Future[_T]") -> None:
141 """Chain two futures together so that when one completes, so does the other.
142
143 The result (success or failure) of ``a`` will be copied to ``b``, unless
144 ``b`` has already been completed or cancelled by the time ``a`` finishes.
145
146 .. versionchanged:: 5.0
147
148 Now accepts both Tornado/asyncio `Future` objects and
149 `concurrent.futures.Future`.
150
151 """
152
153 def copy(future: "Future[_T]") -> None:
154 assert future is a
155 if b.done():
156 return
157 if hasattr(a, "exc_info") and a.exc_info() is not None: # type: ignore
158 future_set_exc_info(b, a.exc_info()) # type: ignore
159 else:
160 a_exc = a.exception()
161 if a_exc is not None:
162 b.set_exception(a_exc)
163 else:
164 b.set_result(a.result())
165
166 if isinstance(a, Future):
167 future_add_done_callback(a, copy)
168 else:
169 # concurrent.futures.Future
170 from tornado.ioloop import IOLoop
171
172 IOLoop.current().add_future(a, copy)
173
174
175def future_set_result_unless_cancelled(

Callers 4

_return_resultMethod · 0.90
with_timeoutFunction · 0.90
run_in_executorMethod · 0.90
wrapperFunction · 0.85

Calls 3

future_add_done_callbackFunction · 0.85
add_futureMethod · 0.80
currentMethod · 0.80

Tested by

no test coverage detected