# ReportViewer.CancellationToken

## Content

# Class: CancellationToken

[ReportViewer](../modules/ReportViewer).CancellationToken

Represents a cancellation token.

**`example`**
```ts
const { token, cancel } = CancellationToken.create();
cancel('Stopped by user');
```

## Table of contents

### Properties

- [parentToken](ReportViewer.CancellationToken#parenttoken)

### Accessors

- [isCancellationRequested](ReportViewer.CancellationToken#iscancellationrequested)
- [promise](ReportViewer.CancellationToken#promise)

### Methods

- [register](ReportViewer.CancellationToken#register)
- [create](ReportViewer.CancellationToken#create)

## Properties

### <a id="parenttoken" name="parenttoken"></a> parentToken

• `Optional` `Readonly` **parentToken**: [`CancellationToken`](ReportViewer.CancellationToken)

Gets the parent token, if any.

## Accessors

### <a id="iscancellationrequested" name="iscancellationrequested"></a> isCancellationRequested

• `get` **isCancellationRequested**(): `boolean`

Gets a value indicating whether cancellation is requested.

#### Returns

`boolean`

___

### <a id="promise" name="promise"></a> promise

• `get` **promise**(): `Promise`<`any`\>

Gets a promise that resolves when cancellation is requested.

#### Returns

`Promise`<`any`\>

## Methods

### <a id="register" name="register"></a> register

▸ **register**(`callback`): `void`

Registers a cancellation handler.

**`example`**
```ts
token.register((reason) => console.log(reason));
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `callback` | (`reason`: `any`) => `any` | The callback invoked when cancellation is requested. |

#### Returns

`void`

___

### <a id="create" name="create"></a> create

▸ `Static` **create**(`parentToken?`): `Object`

Creates a cancellation token and cancel callback.

**`example`**
```ts
const { token, cancel } = CancellationToken.create();
cancel(new Error('Cancelled'));
```

#### Parameters

| Name | Type | Description |
| :------ | :------ | :------ |
| `parentToken?` | [`CancellationToken`](ReportViewer.CancellationToken) | The optional parent token to link cancellation. |

#### Returns

`Object`

The token and a function that triggers cancellation.

| Name | Type |
| :------ | :------ |
| `token` | [`CancellationToken`](ReportViewer.CancellationToken) |
| `cancel` | (`e`: `any`) => `void` |
