public BatchOperator(
            BatchOperatorOptions <T> options,
            ILogger <BatchOperator <T> > logger)
        {
            if (options.BufferTime == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (options.BufferCount == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _options = options;
            _logger  = logger;
            if (options.CacheDataFunc != null)
            {
                _cacheData = options.CacheDataFunc.Invoke();
            }

            _subject
            .Buffer(options.BufferTime.Value, options.BufferCount.Value)
            .Where(x => x.Count > 0)
            .Select(x => Observable.FromAsync(DoManyAsync(x)))
            .Concat()
            .Subscribe();
        }
Exemple #2
0
        public ChannelBatchOperator(
            BatchOperatorOptions <T> options,
            ILogger <ChannelBatchOperator <T> > logger)
        {
            if (options.BufferTime == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (options.BufferCount == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _options        = options;
            _logger         = logger;
            _doManyFuncName = _options.DoManyFuncName ?? _options.DoManyFunc.ToString();
            if (options.CacheDataFunc != null)
            {
                _cacheData = options.CacheDataFunc.Invoke();
            }

            _channel = Channel.CreateUnbounded <BatchItem>();

            _task = Task.Run(ConsumeTasks);
        }