---
title: "TaskWait"
language: "en"
type: "Symbol"
summary: "TaskWait[task] waits for the specified task to be completely finished."
canonical_url: "https://reference.wolfram.com/language/ref/TaskWait.html"
source: "Wolfram Language Documentation"
related_guides: 
  - 
    title: "Background & Scheduled Tasks"
    link: "https://reference.wolfram.com/language/guide/BackgroundAndScheduledTasks.en.md"
related_functions: 
  - 
    title: "TaskObject"
    link: "https://reference.wolfram.com/language/ref/TaskObject.en.md"
  - 
    title: "SessionSubmit"
    link: "https://reference.wolfram.com/language/ref/SessionSubmit.en.md"
  - 
    title: "LocalSubmit"
    link: "https://reference.wolfram.com/language/ref/LocalSubmit.en.md"
  - 
    title: "CloudSubmit"
    link: "https://reference.wolfram.com/language/ref/CloudSubmit.en.md"
  - 
    title: "URLSubmit"
    link: "https://reference.wolfram.com/language/ref/URLSubmit.en.md"
  - 
    title: "WaitAll"
    link: "https://reference.wolfram.com/language/ref/WaitAll.en.md"
---
# TaskWait

TaskWait[task] waits for the specified task to be completely finished.

## Details and Options

* ``task`` can be either a ``TaskObject`` or task identifier string for a specific task.

* ``TaskWait[task]`` blocks until ``task`` is completely finished, then returns the ``TaskObject[…]`` representing ``task``.

* For a scheduled task, ``TaskWait[task]`` waits until all instances of the task specified in the schedule have been executed.

* The following option can be given:

[`TimeConstraint`](https://reference.wolfram.com/language/ref/TimeConstraint.en.md) 	[`Infinity`](https://reference.wolfram.com/language/ref/Infinity.en.md)	maximum time to wait before returning

* ``TaskWait`` has attribute ``Listable``.

---

## Examples (5)

### Basic Examples (4)

Start a task in the current session and wait until it finishes:

```wl
In[1]:=
TaskWait[
	SessionSubmit[Integrate[x ^ 2 Log[x] ^ 5 / Sqrt[1 - x ^ 2], {x, 0, 1}], 
	HandlerFunctions  -> <|"TaskFinished" -> MessageDialog|>, HandlerFunctionsKeys -> {"EvaluationExpression", "EvaluationResult"}]
	]

Out[1]=
5
                                                                                                                                                                                  2   Log[x]
TaskObject[<|TaskUUID -> 8a26708e-2f9d-4583-9766-5d339aca ...                                                      2
                                                                                                                                                                                    Sqrt[1 - x ]
```

---

Wait for a task specified by its UUID:

```wl
In[1]:= obj = LocalSubmit[Pause[20]];uuid = obj["TaskUUID"]

Out[1]= "1aa703d8-d391-4e04-a20e-ff77b6249aa7"

In[2]:= TaskWait[uuid]

Out[2]= TaskObject[<|TaskUUID -> 1aa703d8-d391-4e04-a20e-ff77b6249aa7, TaskEnvironment -> Local, TaskType -> Asynchronous, AsynchronounsTaskID -> 31, EvaluationExpression :> Pause[20], HandlerFunctions -> <||>, HandlerFunctionsKeys -> {EvaluationExpression, EvaluationResult, Failure, EventName, MessageOutput, PrintOutput, Task, TaskStatus, TaskType, TaskUUID}|>]
```

---

Start a task in a separate local kernel and wait until it finishes:

```wl
In[1]:=
TaskWait[LocalSubmit[Integrate[x ^ 2 Log[x] ^ 5 / Sqrt[1 - x ^ 2], {x, 0, 1}], 
	HandlerFunctions  -> <|"TaskFinished" -> MessageDialog|>, HandlerFunctionsKeys -> {"EvaluationExpression", "EvaluationResult"}]]

Out[1]=
5
                                                                                                                                                                                 2   Log[x]
TaskObject[<|TaskUUID -> 09cb462f-27ed-4bbe-9d6c-1275af95a ...                                                       2
                                                                                                                                                                                   Sqrt[1 - x ]
```

---

Starting an asynchronous task and waiting until it completes is equivalent to running the task synchronously:

```wl
In[1]:= TaskWait[URLSubmit["http://www.wolfram.com", HandlerFunctions -> <|"TaskFinished" -> MessageDialog|>]]

Out[1]= TaskObject[<|TaskUUID -> 50d2049c-873e-47d5-a5bf-3b6ff353577d, TaskEnvironment -> External, TaskType -> Asynchronous, AsynchronounsTaskID -> 33, EvaluationExpression :> None, HandlerFunctions -> <||>, HandlerFunctionsKeys -> {TaskStatus}|>]
```

### Options (1)

#### TimeConstraint (1)

Wait for an asynchronous task to complete and then continue, even if it is not done:

```wl
In[1]:=
done = False;
Print["Starting download at ", DateString[]];
task = URLSubmit["http://exampledata.wolfram.com/20mb.dat", HandlerFunctions -> <|
	"BodyReceived" -> ((done = True;MessageDialog["Download complete."])&), 
	"BodyChunkReceived" -> (None&)|>];
TaskWait[task, TimeConstraint -> 1.5]

During evaluation of In[1]:= "Starting download at ""Fri 18 Aug 2017 16:37:58"

Out[1]= TaskObject[<|TaskUUID -> 8a15cdb6-217c-4f6e-9674-0128973c5747, TaskEnvironment -> External, TaskType -> Asynchronous, AsynchronounsTaskID -> 34, EvaluationExpression :> None, HandlerFunctions -> <||>, HandlerFunctionsKeys -> {Body}|>]
```

## See Also

* [`TaskObject`](https://reference.wolfram.com/language/ref/TaskObject.en.md)
* [`SessionSubmit`](https://reference.wolfram.com/language/ref/SessionSubmit.en.md)
* [`LocalSubmit`](https://reference.wolfram.com/language/ref/LocalSubmit.en.md)
* [`CloudSubmit`](https://reference.wolfram.com/language/ref/CloudSubmit.en.md)
* [`URLSubmit`](https://reference.wolfram.com/language/ref/URLSubmit.en.md)
* [`WaitAll`](https://reference.wolfram.com/language/ref/WaitAll.en.md)

## Related Guides

* [Background & Scheduled Tasks](https://reference.wolfram.com/language/guide/BackgroundAndScheduledTasks.en.md)

## History

* [Introduced in 2017 (11.2)](https://reference.wolfram.com/language/guide/SummaryOfNewFeaturesIn112.en.md)