예제 #1
0
 public GrainsPool(StatisticsClient client, int poolSize)
 {
     _grains = new ConcurrentBag <T>();
     _client = client;
     for (int i = 0; i < poolSize; ++i)
     {
         _grains.Add(_client.GetGrain <T>());
     }
 }
예제 #2
0
        public virtual async Task Resize(int poolSize)
        {
            if (poolSize < 1)
            {
                throw new GrainsPoolException($"poolSize should be >= 1!");
            }

            if (_grains.Count >= poolSize)
            {
                while (_grains.Count >= poolSize)
                {
                    _grains.TryTake(out _);
                }
            }
            else
            {
                while (_grains.Count < poolSize)
                {
                    _grains.Add(_client.GetGrain <T>());
                }
            }
        }