> For the complete documentation index, see [llms.txt](https://docs.derw-lang.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.derw-lang.com/hypotheticals/async-await.md).

# Async / await

Async / await is a pattern that can be used for managing asynchronus functions, i.e functions that don't complete each function call in order of calling, but rather based on when the task is finished executing. Working with this pattern in JavaScript typically looks like using Promises and callbacks, and modern JavaScript uses two new keywords to manage this: async, which specifies that a function can use await, and await, which specifies that the function should wait until the function provided is finished executing before moving on.

Derw handles this through the use of `do..return`, blocks which can exist within functions, similarly to `let..in` blocks. The main difference is that `do..return` blocks can have top level function calls (i.e without needing to assign the result to a const or a function). Each function call within a do..return block waits until has finished executing before continuing. This means that the order of definitions matter.

Under the hood, these are compiled to async/await JS blocks.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.derw-lang.com/hypotheticals/async-await.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
