Exemple #1
0
        internal SemaphoreWithKeyDecorator(Func <TMessageType, CancellationToken, Task> handlerFunc, SemaphoreWithKeyDecoratorBuilder <TMessageType, TKeyType> builder)
        {
            this.handlerFunc = handlerFunc;
            this.keySelector = builder.KeySelectorValue;
            this.MaxNumberOfConcurrentMessages = builder.MaxNumberOfConcurrentMessagesValue;

            var equalityComparer = builder.EqualityComparerValue;

            var keySemaphoreValue = builder.KeySemaphoreValue;

            if (keySemaphoreValue == null)
            {
                if (equalityComparer == null)
                {
                    keySemaphoreValue = new KeySemaphore <TKeyType>(this.MaxNumberOfConcurrentMessages);
                }
                else
                {
                    keySemaphoreValue = new KeySemaphore <TKeyType>(this.MaxNumberOfConcurrentMessages, equalityComparer);
                }
            }

            this.keySemaphore = keySemaphoreValue;
        }
 /// <summary>
 ///     Sets the key semaphore
 /// </summary>
 /// <param name="keySemaphore">A key semaphore</param>
 /// <returns>A SemaphoreWithKeyDecoratorBuilder</returns>
 public SemaphoreWithKeyDecoratorBuilder <TMessageType, TKeyType> KeySemaphore(KeySemaphore <TKeyType> keySemaphore)
 {
     this.KeySemaphoreValue = keySemaphore;
     return(this);
 }