# Use with Async/Await

Instead of chaining your async code with `.then().then().then()`, you can use async/await.

Consider this example. First, request `fooData`, then request `barData` and exit the function (also resolving the promise).

```javascript
{
  type: 'TYPE',
  async payload () {
    const fooData = await getFooData();
    const barData = await getBarData(fooData);

    return barData;
  }
}
```

Async/await can be combined with data for [optimistic updates](/redux-promise-middleware/guides/optimistic-updates.md):

```javascript
{
  type: 'OPTIMISTIC_TYPE',
  payload: {
    data: {
      ...
    },
    async promise () {
      ...
    }
  }
}
```

Please note there is no need to `return await` in an async function. [See this ESLint rule for more details](https://eslint.org/docs/rules/no-return-await).


---

# Agent Instructions: 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:

```
GET https://pburtchaell.gitbook.io/redux-promise-middleware/guides/async-await.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
