Skip to main content

async-wrapper

License: MIT Documentation Status github action codecov PyPI version python version

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.

Metadata

Release files for async-wrapper 0.11.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for async-wrapper 0.11.1
File Size Uploaded
async_wrapper-0.11.1.tar.gz 16.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for async-wrapper 0.11.1
File Interpreter ABI Platform
async_wrapper-0.11.1-py3-none-any.whl Python 3 none any Details

Total release size: 37.9 kB

Release files / async_wrapper-0.11.1.tar.gz

Download URL async_wrapper-0.11.1.tar.gz
Size 16.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ae6785912d9f7416c9db2310ef51e01ba2c93928114e39d587cb8463085239a1
BLAKE2b-256 checksum
How to use checksums
f4dbf05bc7ff17a4181ef2b81f4c6853ddb9849d6a956bf577c28aebca221449
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.4.22

Release files / async_wrapper-0.11.1-py3-none-any.whl

Download URL async_wrapper-0.11.1-py3-none-any.whl
Size 21.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c932689447e5c31ae9171583fcc0da037ec4a217bf10f0599fc412f6025066c0
BLAKE2b-256 checksum
How to use checksums
0f6eacbabec053af881bb883392fcbd55b9903d7389ce28d9bcf28463de95b9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.4.22

Release history Release notifications | RSS feed

This release

0.11.1 This release

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.7.1

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.4.8

2 release files

0.4.7

2 release files

0.4.6

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page