public T Spawn <T, TState>(TState state, System.Func <TState, T> constructor, System.Action <T> destructor = null) where T : class { if (Pools.isActive == false) { var instance = constructor.Invoke(state); PoolInternalBaseThread.CallOnSpawn(instance, null); return(instance); } var type = typeof(T); if (this.pool.TryGetValue(type, out var pool) == true) { return((T)pool.Spawn()); } pool = new PoolInternalThread <T, TState>(type, state, constructor, destructor); if (this.pool.TryAdd(type, pool) == true) { return((T)pool.Spawn()); } if (this.pool.TryGetValue(type, out pool) == true) { return((T)pool.Spawn()); } throw new System.Exception("Spawn failed"); }
public static T Create <T>(PoolInternalBaseThread pool) where T : new() { var instance = new T(); PoolInternalBaseThread.CallOnSpawn(instance, pool); return(instance); }
T IPoolImplementation.PoolSpawn <T>(System.Action <T> destructor) { if (this.isNull == true) { var res = new T(); PoolInternalBaseThread.CallOnSpawn(res, null); return(res); } return(this.pools.Spawn <T, byte>(0, (state) => new T(), destructor)); }
T IPoolImplementation.PoolSpawn <T, TState>(TState state, System.Func <TState, T> constructor, System.Action <T> destructor) { if (this.isNull == true) { var res = constructor.Invoke(state); PoolInternalBaseThread.CallOnSpawn(res, null); //ME.WeakRef.Reg(res); return(res); } var instance = this.pools.Spawn <T, TState>(state, constructor, destructor); //ME.WeakRef.Reg(instance); return(instance); }