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.8.3.tar.gz
(26.6 kB
view details)
Built Distribution
File details
Details for the file async_wrapper-0.8.3.tar.gz
.
File metadata
- Download URL: async_wrapper-0.8.3.tar.gz
- Upload date:
- Size: 26.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fbe3706918b66441f5be26095763f957cd0ee9e9f2b3b21b2796dba4ef40efb |
|
MD5 | ec78c4c251f24ffbc6c9588294c6cdb0 |
|
BLAKE2b-256 | be99266c48802e6e202ce3081923a30c366dab09b4a52317c21f72cfd2de0c7e |
File details
Details for the file async_wrapper-0.8.3-py3-none-any.whl
.
File metadata
- Download URL: async_wrapper-0.8.3-py3-none-any.whl
- Upload date:
- Size: 19.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a976ddd8c4dfd65c8092190e3cbde14f707126d2ac5a87398ba0c21b2b04b85 |
|
MD5 | 9c53e5456e2279eddb69a897dc778226 |
|
BLAKE2b-256 | 8acfb0c968225bdac5320f2d36688444097c692af3e15ff36de0e94d835fd4ac |