Create a promise-based async function using the
promisify decorator. It works on both sync and async functions!
from promisio import promisify @promisify async def f(): await asyncio.sleep(1) return 42 @promisify def g(x): return x * 2 async def main(): print(await f()) # prints 42 print(await g(42)) # prints 84 promise = f() # runs function in the background without waiting # ... do other stuff here in parallel with f running await promise # finally wait for f to complete
Promise.reject() are also available. Promises in this package are extended to also support cancellation via the