Suppose there is a library that makes various database queries:
import time
def queryFoo():
time.sleep(4)
return "foo"
def queryBar():
time.sleep(4)
return "bar"
I want to execute those 2 queries concurrently without having to add async
to the method signature or adding a decorator. These functions should not depend on asyncio at all.
What is the best way to utilize those non-async functions within asyncio
?
I am looking for something of the form:
#I need an 'asyncWrapper'
results = asyncio.gather(asyncWrapper(queryFoo()), asyncWrapper(queryBar()))
Thank you in advance for your consideration and response.