Interface IObjectPool<T>

A pool of objects whose disposable lifecycle is tracked.

T - The type of object held in the pool.

interface IObjectPool<T extends IObservableDisposable> {
    added: ISignal<IObjectPool<T>, T>;
    current: null | T;
    currentChanged: ISignal<IObjectPool<T>, null | T>;
    isDisposed: boolean;
    size: number;
    updated: ISignal<IObjectPool<T>, T>;
    dispose(): void;
    filter(fn: (obj: T) => boolean): T[];
    find(fn: (obj: T) => boolean): undefined | T;
    forEach(fn: (obj: T) => void): void;
    has(obj: T): boolean;
}

Type Parameters

Hierarchy

Implemented by

Properties

A signal emitted when an object is added.

This signal does not emit if an object is added using inject().

current: null | T

The current object.

currentChanged: ISignal<IObjectPool<T>, null | T>

A signal emitted when the current object changes.

If the last object being tracked is disposed, null will be emitted.

isDisposed: boolean

Test whether the object has been disposed.

This property is always safe to access.

size: number

The number of objects held by the pool.

updated: ISignal<IObjectPool<T>, T>

A signal emitted when an object is updated.

Methods

  • Dispose of the resources held by the object.

    If the object's dispose method is called more than once, all calls made after the first will be a no-op.

    It is undefined behavior to use any functionality of the object after it has been disposed unless otherwise explicitly noted.

    Returns void

  • Filter the objects in the pool based on a predicate.

    Parameters

    • fn: (obj: T) => boolean

      The function by which to filter.

    Returns T[]

  • Find the first object in the pool that satisfies a filter function.

    Parameters

    • fn: (obj: T) => boolean

      The filter function to call on each object.

      If nothing is found, the value returned is undefined.

    Returns undefined | T

  • Iterate through each object in the pool.

    Parameters

    • fn: (obj: T) => void

      The function to call on each object.

    Returns void