https://github.com/lpthong90/async-iterator
Easy way to use async iterator without take care about asyncio’s TaskGroup.
https://github.com/lpthong90/async-iterator
anyio asynchronous asyncio iterator python
Last synced: 1 day ago
JSON representation
Easy way to use async iterator without take care about asyncio’s TaskGroup.
- Host: GitHub
- URL: https://github.com/lpthong90/async-iterator
- Owner: lpthong90
- License: mit
- Created: 2024-01-05T17:27:45.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-01-07T15:41:53.000Z (almost 2 years ago)
- Last Synced: 2025-02-07T12:53:25.218Z (8 months ago)
- Topics: anyio, asynchronous, asyncio, iterator, python
- Language: JavaScript
- Homepage: http://async-iterator.lpthong90.dev
- Size: 577 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```console
$ pip install async-iterator
---> 100%
Successfully installed async-iterator
```## Basic Usage
```Python
import asyncio
import timefrom async_iterator import aiter, siter
inputs = [1, 2, 3]
async def afunc(it: int) -> int:
await asyncio.sleep(2)
return it + 1def sfunc(it: int) -> int:
time.sleep(2)
return it + 1async 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](https://github.com/lpthong90/async-iterator/blob/main/LICENSE).