AWAITANY

Statement

Syntax

Pauses the current code until the first of the listed tasks ends, fails or is cancelled.

AWAITANY <handle>[, <handle>…]

Parts

<handle>A task handle. List as many as needed, separated by commas.

Good to know

  • AWAITANY never raises the error of a failed task. Check TaskDone() and TaskFailed() afterwards to know which task ended and how.
  • It does not tell which task ended: it gives no value back.
  • The other tasks keep running. Stop the ones you no longer need with CANCELTASK.
  • Refused inside a FUNCTION, like AWAITTASK.

Example

slow AS TASKHANDLEfast AS TASKHANDLESTARTTASK slow, SlowSTARTTASK fast, FastAWAITANY slow, fastIF TaskDone(fast) THEN Console("fast finished first")   ' fast finished firstIF NOT TaskDone(slow) THEN Console("slow still running")   ' slow still runningCANCELTASK slowENDSlow:  Wait(10)RETURN 1Fast:  Sync()RETURN 2
In the manual : The game loop and tasks