import Log from "../Log"; import Timer from "../utils/Timer"; /** * 基类、单例 */ export default class Provider { protected readonly className: string = 'Provider'; private static instance; private static readonly pool = {}; constructor(...args: unknown[]) { } // 返回继承类的实例 public static getInstance(this: T, ...args: unknown[]): InstanceType { if (!this.instance) { let startTime = new Timer(); this.instance = new this(...args); let thatName = this.instance.getClassName() || this.name; Log.info('实例已创建,', thatName, this.instance, '耗时' + startTime.getTimeMs()); Provider.pool[thatName] = this.instance; } return this.instance; } public static getPool() { return { pool: Provider.pool, } } }