Metadata-Version: 2.4
Name: async-wrapper
Version: 0.11.1
Summary: async wrapper
Project-URL: Documentation, https://async-wrapper.readthedocs.io/
Project-URL: Repository, https://github.com/phi-friday/async-wrapper
Author-email: phi <phi.friday@gmail.com>
License: MIT License
        
        Copyright (c) 2023-2024 Choi Min-yeong
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: AnyIO
Classifier: Framework :: AsyncIO
Classifier: Framework :: Trio
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: Implementation :: CPython
Requires-Python: >=3.9
Requires-Dist: anyio>=4.0.0
Requires-Dist: exceptiongroup; python_version < '3.11'
Requires-Dist: sniffio>=1.3.1
Requires-Dist: typing-extensions>=4.4.0
Provides-Extra: docs
Requires-Dist: readthedocs-sphinx-search>=0.3.2; extra == 'docs'
Requires-Dist: sphinx-mdinclude>=0.5.3; extra == 'docs'
Requires-Dist: sphinx-rtd-theme>=2.0.0; extra == 'docs'
Requires-Dist: sphinx>=7.1.0; extra == 'docs'
Provides-Extra: sqlalchemy
Requires-Dist: greenlet; extra == 'sqlalchemy'
Requires-Dist: sqlalchemy[asyncio]; extra == 'sqlalchemy'
Provides-Extra: test
Requires-Dist: aiosqlite>=0.20.0; extra == 'test'
Requires-Dist: pytest-cov>=5.0.0; extra == 'test'
Requires-Dist: pytest-xdist>=3.6.1; extra == 'test'
Requires-Dist: pytest>=8.0.0; extra == 'test'
Requires-Dist: trio>=0.24.0; extra == 'test'
Provides-Extra: uvloop
Requires-Dist: uvloop; (platform_system != 'Windows') and extra == 'uvloop'
Description-Content-Type: text/markdown

# async-wrapper

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Documentation Status](https://readthedocs.org/projects/async-wrapper/badge/?version=latest)](https://async-wrapper.readthedocs.io/en/latest/?badge=latest)
[![github action](https://github.com/phi-friday/async-wrapper/actions/workflows/check.yaml/badge.svg?event=push&branch=main)](#)
[![codecov](https://codecov.io/gh/phi-friday/async-wrapper/graph/badge.svg?token=R1RAQ5F0YD)](https://codecov.io/gh/phi-friday/async-wrapper)
[![PyPI version](https://badge.fury.io/py/async-wrapper.svg)](https://badge.fury.io/py/async-wrapper)
[![python version](https://img.shields.io/pypi/pyversions/async_wrapper.svg)](#)

## how to install
```shell
$ pip install async_wrapper
```

## how to use
```python
from __future__ import annotations

import time

import anyio

from async_wrapper import TaskGroupWrapper, toggle_func


@toggle_func
async def sample_func() -> int:
    await anyio.sleep(1)
    return 1


async def sample_func_2(x: int) -> int:
    await anyio.sleep(1)
    return x


def main():
    result = sample_func()
    assert isinstance(result, int)
    assert result == 1


async def async_main():
    semaphore = anyio.Semaphore(2)

    start = time.perf_counter()
    async with anyio.create_task_group() as task_group:
        wrapper = TaskGroupWrapper(task_group)
        func = wrapper.wrap(sample_func_2, semaphore)
        value_1 = func(1)
        value_2 = func(2)
        value_3 = func(3)
    end = time.perf_counter()

    assert isinstance(value_1.value, int)
    assert isinstance(value_2.value, int)
    assert isinstance(value_3.value, int)
    assert value_1.value == 1
    assert value_2.value == 2
    assert value_3.value == 3
    assert 1.5 < end - start < 2.5


if __name__ == "__main__":
    main()
    anyio.run(async_main)
```

## License

MIT, see [LICENSE](https://github.com/phi-friday/async-wrapper/blob/main/LICENSE).
