# Disposable

Source: https://developers.inkdrop.app/event-subscription/disposable

A handle to a resource that can be disposed.
You can use it by requiring [event-kit](https://github.com/atom/event-kit) module.

```js
import { Disposable } from 'event-kit'
```

---

## Construction `constructor(disposalAction)`

Construct a Disposable

### Parameters

- **disposalAction** ((() => void) | undefined, required)

  A Function to call when `.dispose()` is called for the first time.

```js
const disposable = new Disposable(() => this.destroyResource())
```

---

## Destruction `dispose()`

Perform the disposal action, indicating that the resource associated with
this disposable is no longer needed. You can call this method more than
once, but the disposal action will only be performed the first time.

```js
disposable.dispose();
```

---

## Check if disposable `Disposable.isDisposable(object)`

Ensure that `object` correctly implements the `Disposable` contract.

### Parameters

- **object** (object, required)

  A object.

### Return value

Returns a Boolean indicating whether `object` is a valid `Disposable`.

```js
class ExampleDisposable {
    dispose() {
        // ...
    }
}
Disposable.isDisposable(new ExampleDisposable());
```
