3h-pool 中文文档教程

发布于 3年前 浏览 23 项目主页 更新于 3年前

3h-pool

一个简单的对象池库。

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;

}

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;

}
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文