Три способа выполнить множество задач с 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
#LUNC/USDT analysis :
#LUNC is currently in a downtrend, forming lower lows (LLs) and lower highs (LHs) below the 200 EMA. The price has retraced to the 200 EMA and the resistance zone. It is anticipated that the price will continue its bearish momentum and test lower levels.
TF : 1D
Entry : $0.00008532
Target : $0.00006396
SL : $0.00011356
#LUNC/USDT analysis :
#LUNC is presently in a downtrend, trading below the 200 EMA. The price is facing resistance in the current zone, suggesting a possible reversal point. It is expected that the price will reverse from this resistance area and continue its bearish path, potentially revisiting previous low levels.
TF : 2h
Entry : $0.0000765
Target : $0.0000713
SL : $0.0000788
#LUNC/USDT analysis :
#LUNC is currently experiencing a downtrend, trading below the 200 Exponential Moving Average (EMA). The price is encountering resistance in the current zone, indicating a potential reversal point. It is anticipated that the price will reverse from this resistance area and persist in its bearish trajectory, likely retesting prior low levels.
TF : 30min
Entry : $0.0000764
Target : $0.0000716
SL : $0.0000793
#LUNC/USDT analysis :
#LUNC has experienced a breakout followed by a retest of the resistance zone, which has now transformed into a support zone. It is anticipated that the price will receive support at this level, leading to a potential upward movement to sustain its bullish trend and challenge the previous peak.
TF : 4h
Entry : $0.0000835
Target : $0.0000948
SL : $0.0000785
💰#LUNC reached -Order block zone on Daily Time frame,we need breakup from this area to continue the pump and reach the target price zone (0.0005) otherwise will have a correction until the + order block (the Green zone)✅
❄️@signals_bitcoin_crypto❄️
❄️@Shadow_support0o❄️
💰#LUNC broken up the falling wedge pattern on 12H Time frame,also pullback confirmed,we can buy some lunc here🐋
❄️@signals_bitcoin_crypto❄️
❄️@Shadow_support0o❄️
💰#LUNC rejected from the Trendline on 4H Time frame,we are waiting to see the price reaction to the Support zone..⏳
❄️@signals_bitcoin_crypto❄️
❄️@Shadow_support0o❄️