Три способа выполнить множество задач с 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
#SYS/USDT analysis :
The #SYS is currently in a downtrend, trading below the 200EMA. The price is testing resistance at the current level, and it's expected to decline further from there, potentially testing lower price levels.
TF : 2h
Entry : $0.0487
Target : $0.0410
SL : $0.0522
#SYS/USDT analysis :
#SYS is currently in a correction phase, experiencing a retracement toward the 200 EMA. This presents a potential long trade opportunity on lower time frame. Look for price to retrace and test the support zone for a long entry.
TF : 30min
Entry : $0.0676
Target : $0.0735
SL : $0.0644
#SYS/USDT analysis :
#SYS is currently consolidating sideways within the support zone and is expected to rebound from this level, potentially testing previous highs. It is advisable to wait for a pullback to establish a long position.
TF : 1D
Entry : $0.0964
Target : $0.1257
SL : $0.0822
BUYING $SYS HERE
Exchange: Binance / Binance Futures
Leverage: 3-5x
Breakout confirmed. Market conditions are perfect for an easy 100-200% move on #SYS
Targets: OPEN
SL: Below 0.0254
#SYS result
2 nd target achieved in just 11 hours ✅✅
One more huge quick profit 17% +🤑💰🤑
👉 Still thinking? The more you wait more you lose profit
☎️ Contact @MichaelStrategiesVip for membership and grab next breakout signal