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,
AWAITTASKraises the task's error. Catch it withTRY. - On a cancelled task it returns at once, without an error.
AWAITTASKis a statement.x = AWAITTASK jobcompiles but the program cannot start. WriteAWAITTASK job, thenx = TaskResult(job).- Refused inside a
FUNCTION: "AWAITTASK is not supported inside synchronous FUNCTION". - In a program without
DO, oneAWAITTASKanywhere turns the whole program into a single main program: lifecycle functions such asupdateare no longer found. - Inside a task,
AWAITTASKis not a point whereCANCELTASKcan 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 42In the manual : The game loop and tasks