Exemplo n.º 1
0
        protected ConcurrentFunctionBase(FunctionBaseDecorator funcBase, int maxConcurrency)
        {
            _funcBase      = funcBase;
            _semaphoreSlim = new SemaphoreSlim(maxConcurrency);

            _funcBase.BeforeExecution  += (sender, objects) => BeforeExecution?.Invoke(sender, objects);
            _funcBase.AfterExecution   += (sender, objects) => AfterExecution?.Invoke(sender, objects);
            _funcBase.ExecutionDelayed += (sender, objects) => ExecutionDelayed?.Invoke(sender, objects);
        }
Exemplo n.º 2
0
        protected RateLimitedFunctionBase(FunctionBaseDecorator funcBase, Func <object[], Task <bool> > ignoreRateLimitFunc)
        {
            _funcBase            = funcBase;
            _ignoreRateLimitFunc = ignoreRateLimitFunc;

            _funcBase.BeforeExecution  += (sender, objects) => BeforeExecution?.Invoke(sender, objects);
            _funcBase.AfterExecution   += (sender, o) => AfterExecution?.Invoke(sender, o);
            _funcBase.ExecutionDelayed += (sender, objects) => ExecutionDelayed?.Invoke(sender, objects);
        }
Exemplo n.º 3
0
        protected RetryFunctionBase(FunctionBaseDecorator funcBase, int maxRetryCount, Func <object, bool> retryOnResult, Func <Exception, bool> retryOnException)
        {
            _funcBase         = funcBase;
            _maxRetryCount    = maxRetryCount;
            _retryOnResult    = retryOnResult;
            _retryOnException = retryOnException;

            _funcBase.BeforeExecution  += (sender, objects) => BeforeExecution?.Invoke(sender, objects);
            _funcBase.AfterExecution   += (sender, objects) => AfterExecution?.Invoke(sender, objects);
            _funcBase.ExecutionDelayed += (sender, objects) => ExecutionDelayed?.Invoke(sender, objects);
        }
Exemplo n.º 4
0
        public override async Task <object> ExecuteInnerAsync(object[] arguments)
        {
            TimeSpan rateLimtDelay;

            while ((rateLimtDelay = await GetTimeToNextExecutionAsync(arguments)).Ticks > 0)
            {
                ExecutionDelayed?.Invoke(this, arguments);
                await Task.Delay(rateLimtDelay);
            }

            return(await _funcBase.ExecuteInnerAsync(arguments));
        }