Функция 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
#BIFI/USDT analysis :
#BIFI is currently experiencing a bearish trend, trading below the 200 Exponential Moving Average (EMA). The price is approaching the resistance zone, coinciding with the 200 EMA, and is anticipated to test this level. It is expected to reverse from this point, resuming the bearish momentum and targeting the swing low level.
TF : 2H
Entry : $192
Target : $161
SL : $208
#BIFI/USDT analysis :
#BIFI is in a downtrend, creating new lower lows and lower highs below the 200 EMA. Currently testing a resistance zone, a rejection is anticipated, which will lead to a decline towards the swing low level.
TF : 4h
Entry : $254
Target : $216.7
SL : $274
#BIFI/USDT analysis :
#BIFI has broken and retested the resistance zone, which was formerly a support level. The next expected move is to test the resistance zone and subsequently resume its bearish momentum to revisit previous lows.
TF : 1h
Entry : $281.6
Target : $262.9
SL : $293.3
#BIFI/USDT analysis :
#BIFI has breached previous support zone and is currently trading below it. The price is anticipated to persist in its bearish structure and test prior lows.
TF : 2h
Entry : $307.4
Target : $282.6
SL : $324
Our algorithm detected ascending triangle at #BIFI (4h) chart 👀
Normally, an upside breakout is expected in this triangle type, but indicators give us mixed signals 🤔
Therefore, it would be logical to wait for a directional breakout and then open a position.
Targets are on the chart.
#ZIL LONG
▪Вход ZIL : 0.0225$
▪Тейк: буду обновлять.
#BIFI LONG
▪Вход BIFI : 380$
▪Тейк: буду обновлять.
пс: учитываем, что это альткоины... торгуем соблюдая риски.
LINK - Maximus Trade|TWITTER