Функция 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
#SPELL/USDT analysis :
#SPELL is currently in an uptrend, having demonstrated a rejection after testing the support zone. It is expected that the price will bounce back, resuming its bullish momentum and targeting higher price levels.
TF : 1D
Entry : $0.0010768
Target : $0.0020884
SL : $0.0008066
#SPELL/USDT analysis :
#SPELL has faced resistance at the 200 EMA and has broken below the trendline, indicating a continuation of its downtrend. The formation of lower lows (LLs) and lower highs (LHs) suggests this bearish trend is likely to persist until it reaches previous lows.
TF : 4h
Entry : $0.000740
Target : $0.000550
SL : $0.000865
#SPELL/USDT analysis :
#SPELL is currently in an uptrend, trading above the 200 EMA. The price is undergoing a corrective phase and is expected to test the support zone. A bounce from this level is anticipated, which would allow the price to continue its bullish momentum. It is advisable to wait for the price to retest and show signs of a bounce from the support zone before considering a long entry.
TF : 4H
Entry : $0.0007415
Target : $0.0009850
SL : $0.0006443
#SPELL/USDT analysis :
#SPELL has recently broken below the 200 EMA and previous support levels, and it has retested these levels. It is now likely to continue its bearish momentum and test the previous lows.
TF : 4h
Entry : $0.000537
Target : $0.000492
SL : $0.000561
#SPELL/USDT analysis :
#SPELL is trading in the resistance zone below the 200 EMA. It is expected that the price gonna face rejection at this level and continue moving downwards. It is advisable to wait for the price to break below the $0.000532 level for an entry.
TF : 2H
Entry : $0.000532
Target : $0.000455
SL : $0.000569
#SPELL LONG
📌Симпатично выглядит технически.
▪График слева - зеркальный уровень, мы видим как тестирует с обратной стороны несколько раз, кажется готовится прорыв.
▪График справа - готовится пробой контртрендовой линии, стоим у границы.
▪Вход: 0.000517$
▪Тейк: буду обновлять.
⚠️Cтоп: 0.00044(-14%)
пс: учитываем, что это альткоин... берем не больше 10% в сделку.
LINK - Maximus Trade|TWITTER