aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2024-08-30 22:35:32 -0700
committerZac Medico <zmedico@gentoo.org>2024-08-31 23:58:56 -0700
commit7f6b2b04878209130d44fc06105f521bae2b2173 (patch)
tree8330bdddb07334694c9ffdad7fd799dc1e1e9c5d /lib
parent_safe_loop: Discard wrapped asyncio.run loop that was closed (diff)
downloadportage-7f6b2b04878209130d44fc06105f521bae2b2173.tar.gz
portage-7f6b2b04878209130d44fc06105f521bae2b2173.tar.bz2
portage-7f6b2b04878209130d44fc06105f521bae2b2173.zip
asyncio: Use default sleep implementation when possible
When a loop argument is not given, use the default asyncio sleep implementation and avoid unnecessary _wrap_loop usage. Bug: https://bugs.gentoo.org/761538 Signed-off-by: Zac Medico <zmedico@gentoo.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/portage/util/futures/_asyncio/__init__.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/portage/util/futures/_asyncio/__init__.py b/lib/portage/util/futures/_asyncio/__init__.py
index 23c664e76..a235d8724 100644
--- a/lib/portage/util/futures/_asyncio/__init__.py
+++ b/lib/portage/util/futures/_asyncio/__init__.py
@@ -210,9 +210,12 @@ def sleep(delay, result=None, loop=None):
@param result: result of the future
@type loop: asyncio.AbstractEventLoop (or compatible)
@param loop: event loop
- @rtype: asyncio.Future (or compatible)
- @return: an instance of Future
+ @rtype: collections.abc.Coroutine or asyncio.Future
+ @return: an instance of Coroutine or Future
"""
+ if loop is None:
+ return _real_asyncio.sleep(delay, result=result)
+
loop = _wrap_loop(loop)
future = loop.create_future()
handle = loop.call_later(delay, future.set_result, result)