MCPcopy Index your code
hub / github.com/RustPython/RustPython / _chain_future

Function _chain_future

Lib/asyncio/futures.py:371–412  ·  view source on GitHub ↗

Chain two futures so that when one completes, so does the other. The result (or exception) of source will be copied to destination. If destination is cancelled, source gets cancelled too. Compatible with both asyncio.Future and concurrent.futures.Future.

(source, destination)

Source from the content-addressed store, hash-verified

369
370
371def _chain_future(source, destination):
372 """Chain two futures so that when one completes, so does the other.
373
374 The result (or exception) of source will be copied to destination.
375 If destination is cancelled, source gets cancelled too.
376 Compatible with both asyncio.Future and concurrent.futures.Future.
377 """
378 if not isfuture(source) and not isinstance(source,
379 concurrent.futures.Future):
380 raise TypeError('A future is required for source argument')
381 if not isfuture(destination) and not isinstance(destination,
382 concurrent.futures.Future):
383 raise TypeError('A future is required for destination argument')
384 source_loop = _get_loop(source) if isfuture(source) else None
385 dest_loop = _get_loop(destination) if isfuture(destination) else None
386
387 def _set_state(future, other):
388 if isfuture(future):
389 _copy_future_state(other, future)
390 else:
391 _set_concurrent_future_state(future, other)
392
393 def _call_check_cancel(destination):
394 if destination.cancelled():
395 if source_loop is None or source_loop is dest_loop:
396 source.cancel()
397 else:
398 source_loop.call_soon_threadsafe(source.cancel)
399
400 def _call_set_state(source):
401 if (destination.cancelled() and
402 dest_loop is not None and dest_loop.is_closed()):
403 return
404 if dest_loop is None or dest_loop is source_loop:
405 _set_state(destination, source)
406 else:
407 if dest_loop.is_closed():
408 return
409 dest_loop.call_soon_threadsafe(_set_state, destination, source)
410
411 destination.add_done_callback(_call_check_cancel)
412 source.add_done_callback(_call_set_state)
413
414
415def wrap_future(future, *, loop=None):

Callers 1

wrap_futureFunction · 0.85

Calls 4

isfutureFunction · 0.85
isinstanceFunction · 0.85
_get_loopFunction · 0.85
add_done_callbackMethod · 0.45

Tested by

no test coverage detected