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
from __future__ import annotations
import asyncio
# or(>=py311)
# from asyncio.taskgroups import TaskGroup
from async_wrapper import async_to_sync, get_task_group_factory, get_task_group_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_task_group_wrapper("asyncio")
factory = get_task_group_factory("asyncio")
async with factory() 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.3.tar.gz
(7.5 kB
view hashes)
Built Distribution
Close
Hashes for async_wrapper-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9441750b7b2b14941244db4827aab5783011a223ef7603d8c8b290cb29d2a19e |
|
MD5 | d997d2121f1261a759ee66fda4a5c59c |
|
BLAKE2b-256 | 2cc3968a58bfb562a46ae2e70018e9b5f74a42b1a6cd738794037cf4f180baaf |