Функция asyncio.wait() это еще один способ вызвать множество асинхронных задач.
Она работает в нескольких режимах.
1. Самый простой - ждем завершения всех задач
async def main():
tasks = [asyncio.create_task(do_it(i)) for i in range(10)]
done, pending = await asyncio.wait(
tasks,
return_when=asyncio.ALL_COMPLETED
)
for task in done:
try:
print(task.result())
except Exception as e:
print(e)
Очень похоже на gather, но работает не так.
▫️возвращает не результаты, а два сета с объектами Task у которых можно забрать результат через task.result() если они в списке done
▫️не гарантирует порядок результатов так как оба объекта это set
▫️не выбрасывает исключение когда оно появляется, а сохраняет его в Task. Исключение появится когда попробуете забрать резултьтат.
2. Ждем завершения первой задачи, даже если там ошибка.
async def main():
tasks = [asyncio.create_task(do_it(i)) for i in range(3)]
done, pending = await asyncio.wait(
tasks,
return_when=asyncio.FIRST_COMPLETED
)
# в done может быть несколько задач!
for task in done:
try:
print(task.result())
except Exception as e:
print(f"Fail: {e}")
# Оставшиеся задачи в pending, как правило, нужно отменить, иначе они будут продолжать работать
for task in pending:
task.cancel()
В сете done будут таски которые успели завершится, причем как успешно так и нет.
3. До первой ошибки.
Тоже самое, но с аргументом FIRST_EXCEPTION
done, pending = await asyncio.wait(
tasks,
return_when=asyncio.FIRST_EXCEPTION
)
Функция завершается как только первая задача упадет с ошибкой.
Учтите, что в любом случае done вы можете обранужить несколько задач, как с ошибками так и успешные.
↗️ Полный листинг примеров здесь
#async
Lookonchain | ꘜ
A newly created wallet (0xa523) deposited 23.52M $USDC into #Hyperliquid to buy 466,421 $HYPE ($21.5M) and 2.16M $Fartcoin ($2.12M) in the past 7 hours.
https://hypurrscan.io/address/0xa5232e97b4ded3d2EF25Be059c3489e61Be475Aa
A newly created wallet deposited $3.18M $USDC into #HyperLiquid and opened an $ETH long position with 20x leverage.
The whale is likely to increase the position or open a new one.
@Runlifenick_fx✅
A mysterious whale wallet 0x579f has deposited $2.91M USDC into #Hyperliquid over the last 48 hours — taking massive leveraged bets across three major assets:
• Short 232 BTC (~$25M)
• Short 5,810 ETH (~$22.7M)
• Long 44.79M ENA (~$21.3M)
That’s a combined open position of nearly $70M, signaling a strong rotation from majors to ENA.
https://hypurrscan.io/address/0x579f4017263b88945d727a927bf1e3d061fee5ff
A whale recently created a new wallet (0xb0a0) and deposited $4 million USDC into #Hyperliquid, signaling a major move to accumulate $HYPE.
So far, the wallet has purchased 58,778 $HYPE worth approximately $2.89 million.
https://hypurrscan.io/address/0xb0a0f97898682E3c0A83633DF67E67249d6B12fa
As $UNI is trading at ~$10, a whale holding a $UNI long position with 10x leverage currently has a floating profit of $3M on #HyperLiquid.
The whale also has long positions on $ETH (25x), $BTC and $SOL with 20x leverage, with floating profit of $9.38M.
Overall, the whale is making $31.9M.
https://hyperbot.network/trader/0x9263c1bd29aa87a118242f3fbba4517037f8cc7a
A newly created wallet "0x01f" deposited 242 $ETH into #HyperLiquid to sell, then opened a 3,286.46 $ETH short position with 20x leverage valued at ~$7M.
https://hyperdash.com/address/0x01f135c734b4aae018ebf4e7995c560a38422e50
https://x.com/OnchainLens/status/2041019716492537964
Follow @onchainlens for more onchain updates
After 5 months, a whale deposited $1M $USDC into #HyperLiquid and opened a 20,000 $BRENTOIL long position with 20x leverage.
Previously, the whale has made over $12.44M.
https://hyperbot.network/trader/0x9aB1c356E6Af86361446497FCe954B3CDF940206
https://x.com/OnchainLens/status/2040359551682412700
Follow @onchainlens for more onchain updates
A wallet deposited $2.25M $USDC into #HyperLiquid and opened a 2,271.55 $GOLD ($10M) long position with 10x leverage. https://hyperbot.network/trader/0x06a33efba1ea066af486d3d8b89eea896ec1cf69 https://x.com/OnchainLens/status/2036242636579938809 Follow @OnchainLens…
Machi deposited another $300K USDC into #HyperLiquid to increase his $ETH (25x) long position.
Earlier, Machi partially closed the position at a loss to avoid liquidation.
Machi’s loss is now over $31.29M.
https://hyperbot.network/trader/0x020ca66c30bec2c4fe3861a94e4db4a498a35872
https://x.com/OnchainLens/status/2039617823027425483
Follow @onchainlens for more onchain updates
A newly created wallet deposited $9.6M $USDC into #HyperLiquid and opened a $CL long position with 20x leverage. The position is still increasing. https://hyperbot.network/trader/0x9D32884370875f2960D5CC4b95Be26687d69Aff5 https://x.com/OnchainLens/statu…