Три способа выполнить множество задач с 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
#DGB/USDT analysis :
#DGB is expected to retest the 200 EMA before continuing its bearish trend. This creates a potential buying opportunity on lower time frames (LTF), and the current level is a good point for long trades.
TF : 4H
Entry : $0.00865
Target : $0.00970
SL : $0.00797
#DGB/USDT analysis :
#DGB is currently in a downtrend, consistently making new lows while trading below the 200 EMA. The price is now showing a retracement towards the 200 EMA and the resistance zone. It is expected to reverse and continue its bearish momentum. It is recommended to wait for the price to retest this zone and demonstrate rejection before considering a short entry.
TF : 1D
Entry : $0.00703
Target : $0.00541
SL : $0.00814
#DGB/USDT analysis :
#DGB has broken the support levels and has retested the zone, which is now acting as resistance for the price. The price is expected to decline from this level and test the previous swing low.
TF : 4H
Entry : $0.00662
Target : $0.00634
SL : $0.00681
#DGB/USDT analysis -
The current price movement of #DGB shows a rejection from the resistance zone after establishing a lower low. There is an anticipation of further decline from this point with a potential retest of the previous low. To effectively manage risk, it is advisable to set a stop loss above the rejection zone.
TF : 1h
Entry : $0.00716
Target : $0.00616
SL : $0.00757
#DGB👀
The second chart fully and automatically generated by our algorithm 🤖
All drawings are based on only mathematical values and calculations instead of emotions.
Interested? Check out www.coinlegs.com
#DGB hit 34 today 🔼
Trade opened on 24 March ✨
In both spot n future
Join team @CryptoProfitCoach🔝
⭐⭐ Lifetime Membership opened for a limited time⭐👈👇👇
🟥Multiply your wealth into multiple folds and Get Unique opportunity to trade with @CryptoProfitCoach
✨Buy when he buy sell when he sell...Know what Gem he holding✨
Join team @CryptoProfitCoach🟥
for mega gains and multiply your wealth
✅ Get personalized attention in every trade
✅More trades and Mega profits.
✨ Inside info/Secret info of Coin
✅No.1 Pump Tracking Services.
✅ High End Profit Targets
✅ 24x7 Support in all trades
✅ Get Entry n High end profit Exit with Team in every trade
✨Discounted price -500$ for a year with 24x7 chat support ✅
✨Today's decision can change your tommorrow✨
https://forms.gle/U519Ye8sCmvVE2Pv9
🟥Click here 👆👆✨✨