JSPM

3h-pool

0.1.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q18800F
  • License MIT

A simple object pool lib.

Package Exports

  • 3h-pool
  • 3h-pool/dist/3h-pool.min.js
  • 3h-pool/dist/3h-pool.umd.min.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (3h-pool) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

3h-pool

A simple object pool lib.

API Reference

// Access the APIs via `require('3h-pool')`
// or `HP.*`(UMD namespace).
export as namespace HP;

/**
 * Type of pool creators.
 */
export declare type PoolCreator<T> = () => T;

/**
 * Type of pool processors.
 */
export declare type PoolProcessor<T> = (object: T) => void;

/**
 * Type of pool options.
 */
export interface PoolOptions<T> {

    /**
     * The creator of objects.
     */
    create: PoolCreator<T>;

    /**
     * The initializer of objects,
     * which will be invoked to initialize
     * objects that will be returned by `pop`.
     */
    init?: PoolProcessor<T> | null;

    /**
     * The cleaner of objects,
     * which will be invoked to clear
     * objects that are received by `push`.
     */
    clear?: PoolProcessor<T> | null;

    /**
     * The initial pool size.
     * (`prepare(initSize)` will be executed.)
     */
    initSize?: number;

}

/**
 * Class of object pools.
 */
export declare class Pool<T> {

    /**
     * Constructor {@link Pool}.
     */
    constructor(options: PoolOptions<T>);

    /**
     * Creator of objects.
     */
    create: PoolCreator<T>;

    /**
     * The initializer of objects,
     * which will be invoked to initialize
     * objects that will be returned by `pop`.
     */
    init: PoolProcessor<T> | null;

    /**
     * The cleaner of objects,
     * which will be invoked to clear
     * objects that are received by `push`.
     */
    clear: PoolProcessor<T> | null;

    /**
     * Internal pool.
     */
    pool: T[];

    /**
     * Prepare specific amount of objects in the pool.
     */
    prepare(count: number): void;

    /**
     * Get an object from the pool.
     */
    pop(): T;

    /**
     * Put an object into the pool. (recycle)
     */
    push(object: T): void;

}