Python functions agnostic towards being called with await or otherwise.
Project description
asyncgnostic
Python functions agnostic towards being called with await or otherwise.
Uses multiple dispatch to automatically call asynchronous or synchronous function based on calling context.
Example:
import asyncio
from asyncgnostic import awaitable
def handler() -> str:
return "Running Sync"
@awaitable(handler)
async def handler() -> str:
return "Running Async"
def sync_main():
print("sync context", handler())
async def async_main():
print("async context:", await handler())
sync_main()
asyncio.run(async_main())
Output:
sync context Running Sync
async context: Running Async
Credits:
Gratefully borrowed improvements from curio.
Reference:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
asyncgnostic-0.1.0.tar.gz
(2.7 kB
view hashes)
Built Distribution
Close
Hashes for asyncgnostic-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a45b89ed584be290bba313aa03c2fedfc7aedb89bd64cc4fec3f7c16ba371fb3 |
|
MD5 | 28045788deeeb18c1a0241917e296756 |
|
BLAKE2b-256 | 9de7eb5cbc557f810b85dbb80f207797d60ed00f29ddc1a75a692299eade7165 |