MCPcopy
hub / github.com/scrapy/scrapy / deferred_f_from_coro_f

Function deferred_f_from_coro_f

scrapy/utils/defer.py:406–419  ·  view source on GitHub ↗

Convert a coroutine function into a function that returns a Deferred. The coroutine function will be called at the time when the wrapper is called. Wrapper args will be passed to it. This is useful for callback chains, as callback functions are called with the previous callback result.

(
    coro_f: Callable[_P, Awaitable[_T]],
)

Source from the content-addressed store, hash-verified

404
405
406def deferred_f_from_coro_f(
407 coro_f: Callable[_P, Awaitable[_T]],
408) -> Callable[_P, Deferred[_T]]:
409 """Convert a coroutine function into a function that returns a Deferred.
410
411 The coroutine function will be called at the time when the wrapper is called. Wrapper args will be passed to it.
412 This is useful for callback chains, as callback functions are called with the previous callback result.
413 """
414
415 @wraps(coro_f)
416 def f(*coro_args: _P.args, **coro_kwargs: _P.kwargs) -> Deferred[_T]:
417 return deferred_from_coro(coro_f(*coro_args, **coro_kwargs))
418
419 return f
420
421
422def maybeDeferred_coro(

Callers 2

fetchMethod · 0.90
_assert_resultMethod · 0.90

Calls

no outgoing calls

Tested by 1

_assert_resultMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…