No project description provided
Project description
async-iterator
Easy way to use async iterator without take care about asyncio’s TaskGroup.
Documentation: https://async-iterator.lpthong90.dev
Source Code: https://github.com/lpthong90/async-iterator
The package helps to use async iterator without take care about asyncio's taskgroup.
Installation
$ pip install async-iterator
---> 100%
Successfully installed async-iterator
Basic Usage
import asyncio
import time
from async_iterator import aiter, siter
inputs = [1, 2, 3]
async def afunc(it: int) -> int:
await asyncio.sleep(2)
return it + 1
def sfunc(it: int) -> int:
time.sleep(2)
return it + 1
async def amain():
return await aiter(afunc)(inputs)
def smain():
return siter(sfunc)(inputs)
if __name__ == "__main__":
format = "%Y-%m-%d %H:%M:%S"
print(time.strftime(format))
print("async", asyncio.run(amain())) # it takes ~2 seconds
print(time.strftime(format))
print("sync", smain()) # it takes ~6 seconds
print(time.strftime(format))
Output
2024-01-06 00:58:54
async [2, 3, 4]
2024-01-06 00:58:56
sync [2, 3, 4]
2024-01-06 00:59:02
License
This project is licensed under the terms of the MIT 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_iterator-0.1.1.tar.gz
(2.8 kB
view details)
Built Distribution
File details
Details for the file async_iterator-0.1.1.tar.gz
.
File metadata
- Download URL: async_iterator-0.1.1.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.8.18 Linux/6.2.0-1018-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 645699396d24ee15f26b8ac5d7b7d390b1afad1ede2eb615a37f37a4285cd9ac |
|
MD5 | 9106616262cb565214b8d3b5546333f7 |
|
BLAKE2b-256 | e03293fd654d31835e3df7bd0071878e9eea7158ee6a47459c8d1ee5553629ca |
File details
Details for the file async_iterator-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: async_iterator-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.8.18 Linux/6.2.0-1018-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3d79b6306932ee71bf4436f2ea488eea31afb5c522094f2764e788713782c1f4 |
|
MD5 | e3e707a5a4f8cba2245c818df564e99e |
|
BLAKE2b-256 | fefde6732dda81829c614f61fae92425fd24b3593afbe38a34e350c14fca7a69 |