> For the complete documentation index, see [llms.txt](https://docs.hong97.ltd/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.hong97.ltd/javascript/js/promise.md).

# Promise

## 时序调用链

多个 Promise 之间可以组成时序调用链，如有三个回调函数 `[func1, func2, func3]` ，它们依次在上一个 Promise resolve 后执行：

```javascript
p.then(func1).then(func2).then(func3)
```

上面这样的形式还可以使用 `reduce` 实现：

```javascript
function func1() { console.log('func1') }

function func2() { console.log('func2') }

function func3() { console.log('func3') }

[func1, func2, func3].reduce((p, f) => p.then(f), Promise.resolve('init'))

// output:
// func1
// func2
// func3
```


---

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

```
GET https://docs.hong97.ltd/javascript/js/promise.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.
