Metadata-Version: 2.1
Name: asyncgnostic
Version: 0.1.0
Summary: Python functions agnostic towards being called with await or otherwise.
License: MIT
Author: Harshad Sharma
Author-email: harshad@sharma.io
Requires-Python: >=3.9,<4.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Description-Content-Type: text/markdown

# asyncgnostic

Python functions agnostic towards being called with await or otherwise.

Uses [multiple dispatch](https://en.wikipedia.org/wiki/Multiple_dispatch)
to automatically call asynchronous or synchronous function based on calling context.

## Example:

```python
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:

```console
sync context Running Sync
async context: Running Async
```
## Credits:

Gratefully borrowed improvements from [curio](https://github.com/dabeaz/curio/).

Reference:
  - https://mastodon.sharma.io/@harshad/110476942596328864
  - https://mastodon.social/@dabeaz/110477080111974062
  - https://github.com/dabeaz/curio/blob/master/curio/meta.py

