Track run_in_background

This commit is contained in:
Erik Johnston 2024-07-02 16:26:26 +01:00
parent 032c0d9970
commit 7a0d090adc

View file

@ -821,13 +821,15 @@ def run_in_background(
d: "defer.Deferred[R]"
if isinstance(res, typing.Coroutine):
# Wrap the coroutine in a `Deferred`.
d = defer.ensureDeferred(res)
d = defer.ensureDeferred(measure_coroutine(current.name, res))
elif isinstance(res, defer.Deferred):
d = res
elif isinstance(res, Awaitable):
# `res` is probably some kind of completed awaitable, such as a `DoneAwaitable`
# or `Future` from `make_awaitable`.
d = defer.ensureDeferred(_unwrap_awaitable(res))
d = defer.ensureDeferred(
measure_coroutine(current.name, _unwrap_awaitable(res))
)
else:
# `res` is a plain value. Wrap it in a `Deferred`.
d = defer.succeed(res)