Skip to main content

A simple library for unblocking asynchronous code

Project description

as-async

Small python library to unblock sync functions and generators

Installation

    pip install as-async

Examples

basic usage

   import time
   import asyncio
   from concurrent.futures import ThreadPoolExecutor

   from as_async import as_async

   @as_async()
   def long_running_function():
       time.sleep(5)
       return "Finished"

   async def main():
       result = await long_running_function()
       print(result)

   asyncio.run(main())

specify loop and or executor

    import time
    import asyncio
    from concurrent.futures import ThreadPoolExecutor

    from as_async import as_async_generator

    @as_async_generator(loop=asyncio.get_event_loop(), executor=ThreadPoolExecutor(max_workers=5))
    def long_running_generator():
        for i in range(5):
            time.sleep(1)  # Simulate a long-running operation
            yield i

    async def main():
        async for value in long_running_generator():
            print(value)

    asyncio.run(main())

License

This project is licensed under the MIT License - see the LICENSE file for details

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

as-async-1.0.0.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

as_async-1.0.0-py3-none-any.whl (3.8 kB view hashes)

Uploaded Python 3

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