コード例 #1
0
ファイル: DataLoaderBase.cs プロジェクト: zmarty/hotchocolate
 /// <summary>
 /// Initializes a new instance of the <see cref="DataLoader{TKey, TValue}"/> class.
 /// </summary>
 /// <param name="batchScheduler">
 /// A scheduler to tell the <c>DataLoader</c> when to dispatch buffered batches.
 /// </param>
 /// <param name="options">
 /// An options object to configure the behavior of this particular
 /// <see cref="DataLoader{TKey, TValue}"/>.
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// Throws if <paramref name="options"/> is <c>null</c>.
 /// </exception>
 protected DataLoaderBase(IBatchScheduler batchScheduler, DataLoaderOptions <TKey>?options)
 {
     _options          = options ?? new DataLoaderOptions <TKey>();
     _cache            = _options.Cache ?? new TaskCache(_options.CacheSize);
     _cacheKeyResolver = _options.CacheKeyResolver ?? ((TKey key) => key);
     _batchScheduler   = batchScheduler;
     _maxBatchSize     = _options.GetBatchSize();
 }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="DataLoaderBase{TKey, TValue}"/> class.
        /// </summary>
        /// <param name="options">
        /// A configuration for <c>DataLoaders</c>.
        /// </param>
        /// <param name="cache">
        /// A cache instance for <c>Tasks</c>.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Throws if <paramref name="options"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// Throws if <paramref name="cache"/> is <c>null</c>.
        /// </exception>
        protected DataLoaderBase(DataLoaderOptions <TKey> options, ITaskCache <TValue> cache)
        {
            _options = options ??
                       throw new ArgumentNullException(nameof(options));
            _buffer           = new TaskCompletionBuffer <TKey, TValue>();
            _cache            = cache ?? throw new ArgumentNullException(nameof(cache));
            _cacheKeyResolver = _options.CacheKeyResolver ??
                                ((TKey key) => key);

            StartAsyncBackgroundDispatching();
        }