AWAITTASK

Statement

Syntax

Pauses the current code until a task ends. The Engine keeps drawing frames in the meantime.

AWAITTASK <handle>

Parts

<handle>A task handle: a variable filled by STARTTASK.

Good to know

  • If the task failed, AWAITTASK raises the task's error. Catch it with TRY.
  • On a cancelled task it returns at once, without an error.
  • AWAITTASK is a statement. x = AWAITTASK job compiles but the program cannot start. Write AWAITTASK job, then x = TaskResult(job).
  • Refused inside a FUNCTION: "AWAITTASK is not supported inside synchronous FUNCTION".
  • In a program without DO, one AWAITTASK anywhere turns the whole program into a single main program: lifecycle functions such as update are no longer found.
  • Inside a task, AWAITTASK is not a point where CANCELTASK can stop it.

Example

job AS TASKHANDLESTARTTASK job, CountDownConsole("started")                           ' startedAWAITTASK jobConsole("result " + Str(TaskResult(job)))    ' result 42ENDCountDown:  FOR i = 3 TO 1 STEP -1    Console("tick " + Str(i))                ' tick 3, tick 2, tick 1    Wait(0.2)  NEXTRETURN 42
In the manual : The game loop and tasks