core3-utils

@wixc3/patterns on Github

Home > @wixc3/patterns > Disposable_2

Disposable_2 class

Warning: This API is now obsolete.

A base class for disposable objects

Signature:

export declare class Disposable 

Example

```ts class MyDisposable extends Disposable { constructor() { super(); this.disposables.add(() => console.log(‘disposed’)); this.setTimeout(() => console.log(‘will be canceled upon disposal’), 1000); } async doSomething() { // will throw if disposed, delays disposal until done is called const done = this.disposalGuard(false, true); try { // do something } finally { // disposal can begin (if dispose was called) done(); } } }

Constructors

Constructor Modifiers Description
[(constructor)(name)](/core3-utils/patterns.disposable_2._constructor_.html) Constructs a new instance of the `Disposable` class

Properties

Property Modifiers Type Description
[disposables](/core3-utils/patterns.disposable_2.disposables.html) `readonly` [Disposables](/core3-utils/patterns.disposables.html)
[isDisposed](/core3-utils/patterns.disposable_2.isdisposed.html) `readonly` boolean returns true if the disposal process started

Methods

Method Modifiers Description
[disposalGuard(options)](/core3-utils/patterns.disposable_2.disposalguard.html) - throws if disposal started/finished - in async mode, delays disposal until the returned fn called
[disposalGuard()](/core3-utils/patterns.disposable_2.disposalguard_1.html)
[disposalGuard(options)](/core3-utils/patterns.disposable_2.disposalguard_2.html)
[dispose()](/core3-utils/patterns.disposable_2.dispose.html) Starts instance disposal: \*\*phase 1: disposing\*\* - isDisposed === true - disposalGuard() will throw - disposalGuard(true) will not throw (for methods that are used in the disposal process) - disposable.dispose is awaited \*\*phase 2: disposed done\*\* - disposalGuard(true) will throw
[setInterval(fn, interval)](/core3-utils/patterns.disposable_2.setinterval.html) a disposal safe setInterval checks disposal before execution and clears the interval when the instance is disposed
[setTimeout(fn, timeout)](/core3-utils/patterns.disposable_2.settimeout.html) a disposal safe setTimeout checks disposal before execution and clears the timeout when the instance is disposed