Три способа выполнить множество задач с 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
#MDT/USDT analysis :
#MDT is currently in a downtrend making new lows. The bearish momentum is expected to continue, potentially leading to further declines. For a short entry, consider waiting for a test of the resistance level before initiating a short position.
TF : 2H
Entry : $0.02883
Target : $0.02495
SL : $0.03150
#MDT/USDT analysis :
#MDT is currently in a downtrend, consistently forming lower lows (LLs) and lower highs (LHs) below the 200 EMA. The price is anticipated to continue its bearish momentum and test lower levels. It is recommended to wait for a pullback for a short entry opportunity.
TF : 4H
Entry : $0.05060
Target : $0.04127
SL : $0.05536
#MDT/USDT analysis :
#MDT is currently in an uptrend, characterized by the formation of higher highs (HHs) and higher lows (HLs). The price has retraced to test the 200 EMA, successfully forming a higher low before bouncing back. Wait for a breakout of the trendline, as the price is anticipated to test the previous swing high.
TF : 4H
Entry : $0.06650
Target : $0.08500
SL : $0.05715
#MDT/USDT analysis :
#MDT is in an uptrend, forming higher highs (HHs) and higher lows (HLs) above the 200 EMA. The price has recently tested the support zone and has bounced back from that level. It is anticipated that the bullish momentum will continue, leading to a potential test of previous highs.
TF : 2h
Entry : $0.05624
Target : $0.06177
SL : $0.05297
#MDT/USDT analysis :
#MDT is currently retracing back to the 200 EMA while forming higher highs (HHs) and higher lows (HLs) in its structure. The price is bouncing back from the support zone and is expected to test the previous swing high.
TF : 1D
Entry : $0.04253
Target : $0.05229
SL : $0.03668
#MDT/USDT analysis :
Based on the current market analysis, #MDT is currently experiencing a downtrend, trading below the 200 EMA. Following a correction phase, the price has been rejected from the 200 EMA. The anticipated next move is for the downtrend to persist with an impulsive movement, potentially testing previous lows.
TF : 4H
Entry : $0.0364
Target : $0.0290
SL : $0.0405
#MDT reached the ceiling of the trading range on 12H Time frame,we expect another bullish movement incoming..🚀
❄️@signals_bitcoin_crypto❄️
❄️@Shadow_support0o❄️