/// <summary> /// <paramref name="source"/>의 요소를 <paramref name="target"/> 컬렉션에 추가합니다. /// </summary> public static IDisposable AddFromObservable <T>(this IProducerConsumerCollection <T> target, IObservable <T> source) { target.ShouldNotBeNull("target"); source.ShouldNotBeNull("source"); var observer = new DelegateBaseObserver <T>(item => target.TryAdd(item)); return(source.Subscribe(observer)); }
/// <summary> /// <paramref name="source"/>를 모두 병렬로 실행하여, 결과를 <paramref name="target"/> 컬렉션에 요소로 추가한다. /// </summary> /// <typeparam name="TSource">요소의 수형</typeparam> /// <param name="source">병렬 시퀀스</param> /// <param name="target">공급자/소비자 패턴의 컬렉션</param> public static void OutputToProducerConsumerCollection <TSource>(this ParallelQuery <TSource> source, IProducerConsumerCollection <TSource> target) { source.ShouldNotBeNull("source"); target.ShouldNotBeNull("target"); // 병렬로 수행한 결과를 모두 컬렉션에 추가한다. source.ForAll(item => target.TryAdd(item)); }
/// <summary> /// <paramref name="source"/> 시퀀스의 요소를 <paramref name="target"/> 컬렉션에 요소로 추가합니다. /// </summary> public static void AddFromEnumerable <T>(this IProducerConsumerCollection <T> target, IEnumerable <T> source) { target.ShouldNotBeNull("target"); source.ShouldNotBeNull("source"); foreach (var item in source) { target.TryAdd(item); } }
/// <summary> /// 컬렉션의 요소들을 소비자용의 열거자로 반환합니다. /// </summary> public static IEnumerable <T> GetConsumingEnumerable <T>(this IProducerConsumerCollection <T> collection) { collection.ShouldNotBeNull("collection"); T item; while (collection.TryTake(out item)) { yield return(item); } }
/// <summary> /// 지정된 컬렉션의 모든 요소를 제거합니다. /// </summary> public static void Clear <T>(this IProducerConsumerCollection <T> collection) { collection.ShouldNotBeNull("collection"); if (IsDebugEnabled) { log.Debug("공급자-소비자 컬렉션의 모든 요소를 제거합니다..."); } T ignored; while (collection.TryTake(out ignored)) { } }
/// <summary> /// 생성자 /// </summary> /// <param name="innerCollection">내부 버퍼</param> protected ProducerConsumerCollectionBase(IProducerConsumerCollection <T> innerCollection) { innerCollection.ShouldNotBeNull("innerCollection"); InnerCollection = innerCollection; }
/// <summary> /// 생성자 /// </summary> /// <param name="collection"></param> public AsyncProducerConsumerCollection(IProducerConsumerCollection <T> collection) { collection.ShouldNotBeNull("collection"); _collection = collection; }