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.4.7.tar.gz
(11.2 kB
view details)
Built Distribution
File details
Details for the file async_wrapper-0.4.7.tar.gz
.
File metadata
- Download URL: async_wrapper-0.4.7.tar.gz
- Upload date:
- Size: 11.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.6 Linux/5.15.0-1042-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9f2a5524d7906ab1139577f66d1fc0737ae4c982ee4a8754ff290272247eca4e |
|
MD5 | 7d510f1f8ae3af00297c3d04a9b59807 |
|
BLAKE2b-256 | f34a4cf64f11d85a71dadfadcf84eb6117d6aeef5b84b5cc9dc09b8d64a08acf |
File details
Details for the file async_wrapper-0.4.7-py3-none-any.whl
.
File metadata
- Download URL: async_wrapper-0.4.7-py3-none-any.whl
- Upload date:
- Size: 13.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.10.6 Linux/5.15.0-1042-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd103a5f6983a38fe341f832397ecfd7630d4ff2bac0b48d64d382d154e3ce52 |
|
MD5 | e643b20c9ca5c7a666d00cd9b51c94fb |
|
BLAKE2b-256 | e2b4dc5d124dbb7c47d88ba397f4d368f9f647bfc9265ff1e006fd96e6de1776 |