# Rx.SerialDisposable

Represents a disposable resource whose underlying disposable resource can be replaced by another disposable resource, causing automatic disposal of the previous underlying disposable resource.

## Usage #\#

The follow example shows the basic usage of an Rx.SerialDisposable.

```javascript
var serialDisposable = new Rx.SerialDisposable();

var d1 = Rx.Disposable.create(() => console.log('one'));

serialDisposable.setDisposable(d1);

var d2 = Rx.Disposable.create(() => console.log('two'));

serialDisposable.setDisposable(d2);
// => one

serialDisposable.dispose();
// = two
```

### Location

* rx.js

## `SerialDisposable Constructor` #\#

* [`constructor`](#rxserialdisposable)

## `SerialDisposable Instance Methods` #\#

* [`dispose`](#rxserialdisposableprototypedispose)
* [`getDisposable`](#rxserialdisposableprototypegetdisposable)
* [`setDisposable`](#rxserialdisposableprototypesetdisposable)

## `SerialDisposable Instance Properties` #\#

* [`isDisposed`](#isdisposed)

## _SerialDisposable Constructor_ #\#

### `Rx.SerialDisposable()` <a href="#rxserialdisposable" id="rxserialdisposable"></a>

[#](#rxserialdisposable) [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables/serialdisposable.js#L5-L8)

Initializes a new instance of the `Rx.SerialDisposable` class.

#### Example

```javascript
var serialDisposable = new Rx.SerialDisposable();

console.log(serialDisposable.isDisposed);
// => false
```

### Location

* rx.js

## _SerialDisposable Instance Methods_ #\#

### `Rx.SerialDisposable.prototype.dispose()` <a href="#rxserialdisposableprototypedispose" id="rxserialdisposableprototypedispose"></a>

[#](#rxserialdisposableprototypedispose) [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables/serialdisposable.js#L50-L60)

Disposes the underlying disposable as well as all future replacements.

#### Example

```javascript
var serialDisposable = new Rx.SerialDisposable();

var d1 = Rx.Disposable.create(() => console.log('one'));

serialDisposable.setDisposable(disposable);

serialDisposable.dispose();
// => one

var d2 = Rx.Disposable.create(() => console.log('two'));

// => two
```

### Location

* rx.js

### `Rx.SerialDisposable.prototype.getDisposable()` <a href="#rxserialdisposableprototypegetdisposable" id="rxserialdisposableprototypegetdisposable"></a>

[#](#rxserialdisposableprototypegetdisposable) [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables/serialdisposable.js#L16-L18)

Gets the underlying disposable.

#### Returns

_(Disposable)_: The underlying disposable.

#### Example

```javascript
var serialDisposable = new Rx.SerialDisposable();

var disposable = Rx.Disposable.create(() => console.log('disposed'));

serialDisposable.setDisposable(disposable);

var d = serialDisposable.getDisposable();

console.log(d === disposable);
```

### Location

* rx.js

### `Rx.SerialDisposable.prototype.setDisposable(value)` <a href="#rxserialdisposableprototypesetdisposablevalue" id="rxserialdisposableprototypesetdisposablevalue"></a>

[#](#rxserialdisposableprototypesetdisposablevalue) [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables/serialdisposable.js#L24-L36)

Sets the underlying disposable.

#### Arguments

1. `value` _(Disposable)_: The new underlying disposable.

#### Example

```javascript
var serialDisposable = new Rx.SerialDisposable();

var d1 = Rx.Disposable.create(() => console.log('one'));

serialDisposable.setDisposable(d1);

serialDisposable.dispose();
// => one

var d2 = Rx.Disposable.create(() => console.log('two'));

serialDisposable.setDisposable(d2);
// => two
```

### Location

* rx.js

## _SerialDisposable Instance Properties_ #\#

### `isDisposed` <a href="#isdisposed" id="isdisposed"></a>

[#](#isdisposed) [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables/serialdisposable.js#L6)

Gets a value that indicates whether the object is disposed.

#### Example

```javascript
var serialDisposable = new Rx.SerialDisposable();

var disposable = Rx.Disposable.create(() => console.log('disposed'));

serialDisposable.setDisposable(disposable);

console.log(serialDisposable.isDisposed);
// => false

serialDisposable.dispose();
// => disposed

console.log(serialDisposable.isDisposed);
// => true
```

### Location

* rx.js
