---
title: PagePromise
editUrl: false
head: []
template: doc
prev: false
next: false
sidebar:
  hidden: false
  attrs: {}
pagefind: true
draft: false
---

Defined in: [src/core/pagination.ts:19](https://github.com/slingshot/brex/blob/9dff46b5d5637a0dd072bca56d02d8a0f4425312/src/core/pagination.ts#L19)

Return type of every paginated SDK method — both a promise and an iterator:

- `await client.vendors.list()` → the first page;
- `for await (const vendor of client.vendors.list())` → every item, across
  pages, following `next_cursor` automatically;
- `for await (const page of client.vendors.list().pages())` → page-by-page.

Each `await`/iteration starts its own request(s).

## Type Parameters

### P

`P` *extends* [`PageShape`](/brex/api/index/interfaces/pageshape/)

## Implements

- `PromiseLike`\<`P`\>
- `AsyncIterable`\<[`PageItem`](/brex/api/index/type-aliases/pageitem/)\<`P`\>\>

## Constructors

### Constructor

> **new PagePromise**\<`P`\>(`fetchPage`): `PagePromise`\<`P`\>

Defined in: [src/core/pagination.ts:24](https://github.com/slingshot/brex/blob/9dff46b5d5637a0dd072bca56d02d8a0f4425312/src/core/pagination.ts#L24)

#### Parameters

##### fetchPage

(`cursor?`) => `Promise`\<`P`\>

#### Returns

`PagePromise`\<`P`\>

## Methods

### \[asyncIterator\]()

> **\[asyncIterator\]**(): `AsyncGenerator`\<[`PageItem`](/brex/api/index/type-aliases/pageitem/)\<`P`\>, `void`, `undefined`\>

Defined in: [src/core/pagination.ts:47](https://github.com/slingshot/brex/blob/9dff46b5d5637a0dd072bca56d02d8a0f4425312/src/core/pagination.ts#L47)

Iterate every item across all pages.

#### Returns

`AsyncGenerator`\<[`PageItem`](/brex/api/index/type-aliases/pageitem/)\<`P`\>, `void`, `undefined`\>

#### Implementation of

`AsyncIterable.[asyncIterator]`

***

### pages()

> **pages**(): `AsyncGenerator`\<`P`, `void`, `undefined`\>

Defined in: [src/core/pagination.ts:37](https://github.com/slingshot/brex/blob/9dff46b5d5637a0dd072bca56d02d8a0f4425312/src/core/pagination.ts#L37)

Iterate page-by-page, following `next_cursor` until exhausted.

#### Returns

`AsyncGenerator`\<`P`, `void`, `undefined`\>

***

### then()

> **then**\<`TResult1`, `TResult2`\>(`onfulfilled?`, `onrejected?`): `Promise`\<`TResult1` \| `TResult2`\>

Defined in: [src/core/pagination.ts:29](https://github.com/slingshot/brex/blob/9dff46b5d5637a0dd072bca56d02d8a0f4425312/src/core/pagination.ts#L29)

Attaches callbacks for the resolution and/or rejection of the Promise.

#### Type Parameters

##### TResult1

`TResult1` = `P`

##### TResult2

`TResult2` = `never`

#### Parameters

##### onfulfilled?

((`value`) => `TResult1` \| `PromiseLike`\<`TResult1`\>) \| `null`

The callback to execute when the Promise is resolved.

##### onrejected?

((`reason`) => `TResult2` \| `PromiseLike`\<`TResult2`\>) \| `null`

The callback to execute when the Promise is rejected.

#### Returns

`Promise`\<`TResult1` \| `TResult2`\>

A Promise for the completion of which ever callback is executed.

#### Implementation of

`PromiseLike.then`