Skip to main content

async wrapper

Project description

async-wrapper

License: MIT github action PyPI version python version

how to install

$ pip install async_wrapper
# or
$ pip install "async_wrapper[all]"
# or
$ pip install "async_wrapper[anyio]"
# or
$ pip install "async_wrapper[loky]"

how to use

import asyncio

from aiotools import TaskGroup
# or(>=py311)
# from asyncio.taskgroups import TaskGroup

from async_wrapper import async_to_sync, get_taskgroup_wrapper


@async_to_sync("thread")
async def sample_func() -> int:
    await asyncio.sleep(1)
    return 1


result = sample_func()
assert isinstance(result, int)
assert result == 1


async def sample_func_2(x: int) -> int:
    await asyncio.sleep(1)
    return x


async def main():
    wrapper = get_taskgroup_wrapper("asyncio")
    async with TaskGroup() as task_group:
        value_1 = wrapper(sample_func_2, task_group)(1)
        value_2 = wrapper(sample_func_2, task_group)(2)

    assert isinstance(value_1.value, int)
    assert isinstance(value_2.value, int)
    assert value_1.value == 1
    assert value_2.value == 2

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

Uploaded Source

Built Distribution

async_wrapper-0.1.2-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: async_wrapper-0.1.2.tar.gz
  • Upload date:
  • Size: 7.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.6 Linux/5.15.0-1040-azure

File hashes

Hashes for async_wrapper-0.1.2.tar.gz
Algorithm Hash digest
SHA256 eb33c9928f7c9473ff8eb46121a7b2fbf1e6da34b1dd1ce305fe5dc371989c1c
MD5 4ac0a9b64a04c75aecd56182b5672a73
BLAKE2b-256 641a259a96cac4db4139bde6431087bc5f829b8318aaa467ac73c5ec419dd347

See more details on using hashes here.

File details

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

File metadata

  • Download URL: async_wrapper-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.6 Linux/5.15.0-1040-azure

File hashes

Hashes for async_wrapper-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9f940b62eef149144e36fbd67bf931a7960589b464df839821bd6ceb4bf9b10f
MD5 1c0787091fcce1febc931b8984b93d90
BLAKE2b-256 0c9ca76ebd2f0139bf31b6d2d1117cd625a5ac98972b4e6888eaa1868c57712e

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