async wrapper
Project description
async-wrapper
how to install
$ pip install async_wrapper
# or
$ pip install "async_wrapper[all]"
# or
$ pip install "async_wrapper[anyio]"
# or
$ pip install "async_wrapper[loky]"
how to use
import asyncio
from aiotools import TaskGroup
# or(>=py311)
# from asyncio.taskgroups import TaskGroup
from async_wrapper import async_to_sync, get_taskgroup_wrapper
@async_to_sync("thread")
async def sample_func() -> int:
await asyncio.sleep(1)
return 1
result = sample_func()
assert isinstance(result, int)
assert result == 1
async def sample_func_2(x: int) -> int:
await asyncio.sleep(1)
return x
async def main():
wrapper = get_taskgroup_wrapper("asyncio")
async with TaskGroup() as task_group:
value_1 = wrapper(sample_func_2, task_group)(1)
value_2 = wrapper(sample_func_2, task_group)(2)
assert isinstance(value_1.value, int)
assert isinstance(value_2.value, int)
assert value_1.value == 1
assert value_2.value == 2
License
MIT, see LICENSE.
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
async_wrapper-0.1.2.tar.gz
(7.2 kB
view hashes)
Built Distribution
Close
Hashes for async_wrapper-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f940b62eef149144e36fbd67bf931a7960589b464df839821bd6ceb4bf9b10f |
|
MD5 | 1c0787091fcce1febc931b8984b93d90 |
|
BLAKE2b-256 | 0c9ca76ebd2f0139bf31b6d2d1117cd625a5ac98972b4e6888eaa1868c57712e |