UNPKG

nope-js-node

Version:

NoPE Runtime for Nodejs. For Browser-Support please use nope-browser

47 lines (46 loc) 1.58 kB
/** * @author Martin Karkowski * @email m.karkowski@zema.de * @desc [description] */ /** * Sometimes, the creation of an new Instance is very slow. Therefore this Lazy-Constructor could be used. * Instead of creating a new Instance, it looks for a not used and returns that Instance. By returning * the unused Instance it is marked as used. After the usage the instance could marked as unused again. * If there is no unused Instance available an new Instance is created. * * To utilize the Lazy-Constructor a specific create-instance method and a compare function is required. * * @export * @class LazyConstructor * @template T Args which are required to Construct an Instance * @template U Type of the Instance */ export declare class LazyConstructor<T> { private _ctor; private _inactive; /** * Creates an instance of LazyConstructor. * @param {*} _ctor * @param {(a:T,b:t)=>boolean} _equals * @memberof LazyConstructor */ constructor(_ctor: (...arggs: any[]) => T); /** * Creates a new Instance and tries to use an already existing * one if possible. * * @param {T} args An Object containing the args which are required to create an Instance * @returns {U} new Object * @memberof LazyConstructor */ createInstance(...args: any[]): T; /** * Releases a used Instance. Thereby it could be * used again. * * @param {U} instance * @memberof LazyConstructor */ releaseInstance(instance: T): void; }