Три способа выполнить множество задач с asyncio
Функция для примера:
async def do_it(n):
await asyncio.sleep(random.uniform(0.5, 1))
return n
1. Последовательный вызов
async def main():
for i in range(100):
result = await do_it(i)
Такой вызов имеет смысл только тогда, когда результат одной задачи требуется для вызова следующей.
Если они независимы, то это антипаттерн, так как аналогичен простому синхронному вызову по очереди.
2. Упорядоченный результат
async def main():
tasks = [do_it(i) for i in range(100)]
results = await asyncio.gather(*tasks)
Выполняет корутины конкурентно и возвращает результат в виде списка.
Полезен когда требуется получить результаты в том же порядке в котором задачи отправлены.
3. Результат по мере готовности
tasks = [asyncio.create_task(do_it(i)) for i in range(100)]
for cor in asyncio.as_completed(tasks):
result = await cor
Так же выполняет корутины конкурентно, но не гарантирует порядок. Результат возвращается по мере готовности, каждый отдельно.
Полезен когда нужно обработать любой ответ как можно скорее.
#async
⚡️Toncoin: TON Nominated for Best Developer Ecosystem
#TON#developers
Toncoin has announced that TON has been nominated for the Best Ecosystem Program for Developers at the BeInCrypto 100 Awards 2025. Enthusiasts and supporters can participate in public voting to support this achievement.
Source: link
@tonlines
EVAA Celebrates TON Mainnet Anniversary
#TON#developers
EVAA marks the anniversary of The Open Network Mainnet, launched on May 26, 2021. Over four years, the TON ecosystem has flourished with the contributions of active developers and TON Core.
Source: link
@tonlines
Tonnel Network: Telegram’s Financial Growth through Strategic Partnerships
#Telegram#developers
Tonnel Network highlights how Telegram’s financial stability has been strengthened through strategic partnerships with developers. These partnerships involve app and bot development, in-app purchases, and its advertising initiatives.
Source: link
@tonlines
We're a proud sponsor of the first Flow Hackathon – a global competition from 2/21–2/26 to push the limits of #web3#onFlow.
Beyond excited to be involved in the expansion of the #ecosystem and to provide an opportunity for developers to shine! 💡✨
This is what's up:
💰 $500K in prizes
🌐 Virtual & IRL events
📚 Education phase to learn more about building #onFlow
✨ Amazing speakers and judges
👨💻 Empowering #developers to do great things
Are you ready to build awesome innovations and earn prizes for your work?
Register today! 👇
https://hackathon.flow.com