# 11.1 Suspendible units and Await

> A `Suspendible` unit can pause half-way while it waits for something; `Await` marks in the code every point where that pause may happen.

Web page: https://pseudolearn.app/en/spec/tareas/suspendible

> **In one sentence**
>
> A `Suspendible` unit can pause half-way while it waits for something; `Await` marks in the code every point where that pause may happen.

## 11.1.1 How it works

`Subroutine Suspendible` declares a subprogram that **can suspend**: stop running for a moment while it waits for another task, a channel or a host effect. The main algorithm is suspendible without being marked.

Every call to a suspendible unit must be preceded by `Await`. That way, reading the code, you see exactly where the program can pause: nowhere else.

**Figure 11.1-1: Pausing at Await**

Two timelines. Task A works, pauses at Await while task B works, and continues when B hands it the result.

The task runs up to `Await`, pauses while another one works and continues with the result. Outside the marked points it is never interrupted.

### Program: A suspendible call without Await

```pseudolearn
Subroutine Suspendable Doble(n As Integer) As Integer
  Return n * 2;
EndSubroutine

Algorithm SinAguardar
  Write Doble(2);
EndAlgorithm
```

**Diagnostics**
- `suspendibleCallWithoutAwait` (error, 6:9): A call to a suspendable subprogram must use await

*The program finishes with an error.*

`Await` can go in any position of an expression. What was computed before the wait is kept.

> **Limit**
>
> - `Suspendible` is not allowed on `Function`, methods, constructors or function literals.
> - A suspendible unit is not a value: it cannot be stored or passed as a function.
> - `Await` only accepts a call to a suspendible unit or a capability operation; it is forbidden inside `Defer`.

**In short**
- `Suspendible` declares a unit that can pause.
- Every pause point is marked with `Await`.
- Between two `Await`s, a task is not interrupted.

**See also**
- [11.2 Task scopes with Tasks and Spawn](https://pseudolearn.app/en/spec/tareas/ambitos.md)
- [11.3 Channels and Select](https://pseudolearn.app/en/spec/tareas/canales.md)
- [13.3 The task schedule](https://pseudolearn.app/en/spec/motor/agenda.md)
