当前位置: 首页>>代码示例>>C#>>正文


C# Pool.DetachPooledValue方法代码示例

本文整理汇总了C#中Pool.DetachPooledValue方法的典型用法代码示例。如果您正苦于以下问题:C# Pool.DetachPooledValue方法的具体用法?C# Pool.DetachPooledValue怎么用?C# Pool.DetachPooledValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Pool的用法示例。


在下文中一共展示了Pool.DetachPooledValue方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AcquiredInstancesCanBeDetachedFromOwningPoolTest

        public async Task AcquiredInstancesCanBeDetachedFromOwningPoolTest(int poolSize)
        {
            // given
            var pool = new Pool<string>((token) => Guid.NewGuid().ToString(), poolSize);
            var acquiredPooledItem = await pool.AcquirePooledValueAsync();
            var acquiredPooledItemValue = acquiredPooledItem.Value;

            // when
            var detachedValue = pool.DetachPooledValue(acquiredPooledItem);
            
            // then
            pool.TotalInstancesCount.Should().Be(poolSize - 1);
            pool.AvailableInstancesCount.Should().Be(poolSize - 1);
            detachedValue.Should().Be(acquiredPooledItemValue);

            acquiredPooledItem.HasBeenReleasedBackToPool.Should().Be(false);
            acquiredPooledItem.HasBeenDetachedFromPool.Should().Be(true);
        }
开发者ID:jbattermann,项目名称:JB.Common,代码行数:18,代码来源:PoolTests.cs

示例2: AcquiredInstancesCannotBeDetachedFromDifferentPoolTest

        public async Task AcquiredInstancesCannotBeDetachedFromDifferentPoolTest()
        {
            // given
            var owningPool = new Pool<string>((token) => Guid.NewGuid().ToString(), 1);
            var secondPool = new Pool<string>((token) => Guid.NewGuid().ToString());

            var acquiredPooledItem = await owningPool.AcquirePooledValueAsync();

            // when
            Action detachFromPoolAction = () => secondPool.DetachPooledValue(acquiredPooledItem);

            // then
            detachFromPoolAction.ShouldThrow<ArgumentOutOfRangeException>().And.ParamName.Should().Be("pooledValue");

            owningPool.AvailableInstancesCount.Should().Be(0);
            acquiredPooledItem.HasBeenReleasedBackToPool.Should().Be(false);
            acquiredPooledItem.HasBeenDetachedFromPool.Should().Be(false);
        }
开发者ID:jbattermann,项目名称:JB.Common,代码行数:18,代码来源:PoolTests.cs

示例3: AcquiredInstancesCannotBeDetachedMultipleTimesTest

        public async Task AcquiredInstancesCannotBeDetachedMultipleTimesTest()
        {
            // given
            var pool = new Pool<string>((token) => Guid.NewGuid().ToString(), 1);
            var acquiredPooledItem = await pool.AcquirePooledValueAsync();

            // when
            Action detachFromPoolAction = () => pool.DetachPooledValue(acquiredPooledItem);

            // then
            // prior to returning poolsize should be down by one
            detachFromPoolAction.ShouldNotThrow();

            // however a second (or more) time(s) should not be allowed
            detachFromPoolAction.ShouldThrow<ArgumentOutOfRangeException>();
        }
开发者ID:jbattermann,项目名称:JB.Common,代码行数:16,代码来源:PoolTests.cs


注:本文中的Pool.DetachPooledValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。