Skip to main content

async wrapper

Project description

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.

Project details


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.6.2.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

async_wrapper-0.6.2-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file async_wrapper-0.6.2.tar.gz.

File metadata

  • Download URL: async_wrapper-0.6.2.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.12 Linux/6.2.0-1019-azure

File hashes

Hashes for async_wrapper-0.6.2.tar.gz
Algorithm Hash digest
SHA256 ac7b141c96d635ad1f48402a5d0a532fb3911fdabd6f62669709f2e49014efd2
MD5 fa1026ae6a46a5db4e752bf23cdbf80f
BLAKE2b-256 a37fdbacb48db0e1f81ed221135c49c1cf18bb3d4d19858f4043451b47c8b627

See more details on using hashes here.

File details

Details for the file async_wrapper-0.6.2-py3-none-any.whl.

File metadata

  • Download URL: async_wrapper-0.6.2-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.12 Linux/6.2.0-1019-azure

File hashes

Hashes for async_wrapper-0.6.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4b3807f9c8ccf61d677d0f38b4f03b259e937a2ff136fe750a1b9f5e394ff86d
MD5 35f2aa382a337f34039e17231d7e85f0
BLAKE2b-256 a717a406a2737f7ef8f1f174ae2babaac1e72306744966b500113998eb21a8fb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page