Interface IObjectPool<T>

A pool of objects whose disposable lifecycle is tracked.

Typeparam

T - The type of object held in the pool.

interface IObjectPool<T> {
    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): T[];
    find(fn): undefined | T;
    forEach(fn): void;
    has(obj): 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.

Notes

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

isDisposed: boolean

Test whether the object has been disposed.

Notes

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.

    Notes

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

    Undefined Behavior

    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) => boolean)

      The function by which to filter.

        • (obj): boolean
        • Parameters

          • obj: T

          Returns boolean

    Returns T[]

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

    Parameters

    • fn: ((obj) => boolean)

      The filter function to call on each object.

      Notes

      If nothing is found, the value returned is undefined.

        • (obj): boolean
        • Parameters

          • obj: T

          Returns boolean

    Returns undefined | T

  • Iterate through each object in the pool.

    Parameters

    • fn: ((obj) => void)

      The function to call on each object.

        • (obj): void
        • Parameters

          • obj: T

          Returns void

    Returns void