コード例 #1
0
ファイル: ActorFactory.cs プロジェクト: teoadal/velo
        private int CreateOrCheckId(int?id)
        {
            if (id.HasValue)
            {
                var idValue = id.Value;

                if (_actorContext.Contains(idValue))
                {
                    throw Error.AlreadyExists($"Actor with id {idValue} already exists");
                }

                using (Lock.Enter(_freeIds))
                {
                    _freeIds.Remove(idValue);
                }

                return(idValue);
            }

            var actorId = Interlocked.Increment(ref _nextId);

            while (_actorContext.Contains(actorId))
            {
                actorId = Interlocked.Increment(ref _nextId);
            }

            return(actorId);
        }
コード例 #2
0
ファイル: ActorContextShould.cs プロジェクト: teoadal/velo
 public void Contains()
 {
     _actorContext.Add(_actor);
     _actorContext.Contains(_actor.Id).Should().BeTrue();
 }