async wrapper
Project description
async-wrapper
how to install
$ pip install async_wrapper
how to use
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.
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.10.0.tar.gz
(16.1 kB
view details)
Built Distribution
File details
Details for the file async_wrapper-0.10.0.tar.gz
.
File metadata
- Download URL: async_wrapper-0.10.0.tar.gz
- Upload date:
- Size: 16.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | be5730859590366f7b0f8856035ea95612f745ea5c58c2b70d411366c7729a81 |
|
MD5 | cd617a29dc36f9a345b49f3131bc5fca |
|
BLAKE2b-256 | 4941ed0e1c3bf8aeab6a2b75a969b5c46300cbbaa88640084570e19b0a8f62f4 |
File details
Details for the file async_wrapper-0.10.0-py3-none-any.whl
.
File metadata
- Download URL: async_wrapper-0.10.0-py3-none-any.whl
- Upload date:
- Size: 22.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a07a1e745d227160b5f285d0e66615e0fc346c8096ff8f7a17330b94e735593b |
|
MD5 | 3e5f35c91d3371596d72656c8aa2f421 |
|
BLAKE2b-256 | 8087ade26f4f43ee58d977503841ca341593ff50396cd1145fb3ada9fe0c5e00 |