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.0.tar.gz
(2.5 kB
view hashes)
Built Distribution
Close
Hashes for async_iterator-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 49f0cc6c46a052dfbd0a975c39299f4f91f28f6cdc5f602f059a0a323de77247 |
|
MD5 | 837c828a0dd25eb5c2606019e80b117c |
|
BLAKE2b-256 | 9c4ddc97ac4479cee1393734a6dd4dc2e480e1578f09f12e6ff7e03e5c6fb21b |