# Class LittleGhost::Support::CancellationToken

Documentation version: Edge

Canonical HTML: https://littleghostai.org/docs/LittleGhost/Support/CancellationToken.html

CancellationToken lets related work stop cooperatively without killing its
calling thread or fiber. Child tokens make cancellation flow through a run's
tree of work.

Cancellation is idempotent and flows only downward. Long-running extensions
should call #raise_if_cancelled! at bounded intervals.

## Inheritance

`LittleGhost::Support::CancellationToken < Object`

## Class methods

<a id="method-c-new"></a>
### `.new`

```ruby
.new(parent: nil)
```

Optionally attaches this token to `parent`.

## Instance methods

<a id="method-i-cancel"></a>
### `#cancel`

```ruby
#cancel()
```

Cancels this token and all currently attached children.

<a id="method-i-cancelled-3F"></a>
### `#cancelled?`

```ruby
#cancelled?()
```

Indicates whether cancellation has been requested.

<a id="method-i-child"></a>
### `#child`

```ruby
#child()
```

Creates a child cancelled automatically with this token.

<a id="method-i-raise_if_cancelled-21"></a>
### `#raise_if_cancelled!`

```ruby
#raise_if_cancelled!()
```

Raises CancelledError when cancellation has been requested.

<a id="method-i-wait"></a>
### `#wait`

```ruby
#wait(timeout)
```

Waits up to `timeout` seconds for cancellation.
