Lean  $LEAN_TAG$
IBusyCollection.cs
1 /*
2  * QUANTCONNECT.COM - Democratizing Finance, Empowering Individuals.
3  * Lean Algorithmic Trading Engine v2.0. Copyright 2014 QuantConnect Corporation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  *
15 */
16 
17 using System;
18 using System.Collections.Generic;
19 using System.Threading;
20 
22 {
23  /// <summary>
24  /// Interface used to handle items being processed and communicate busy state
25  /// </summary>
26  /// <typeparam name="T">The item type being processed</typeparam>
27  public interface IBusyCollection<T> : IDisposable
28  {
29  /// <summary>
30  /// Gets a wait handle that can be used to wait until this instance is done
31  /// processing all of it's item
32  /// </summary>
34 
35  /// <summary>
36  /// Gets the number of items held within this collection
37  /// </summary>
38  int Count { get; }
39 
40  /// <summary>
41  /// Returns true if processing, false otherwise
42  /// </summary>
43  bool IsBusy { get; }
44 
45  /// <summary>
46  /// Adds the items to this collection
47  /// </summary>
48  /// <param name="item">The item to be added</param>
49  void Add(T item);
50 
51  /// <summary>
52  /// Adds the items to this collection
53  /// </summary>
54  /// <param name="item">The item to be added</param>
55  /// <param name="cancellationToken">A cancellation token to observer</param>
56  void Add(T item, CancellationToken cancellationToken);
57 
58  /// <summary>
59  /// Marks the collection as not accepting any more additions
60  /// </summary>
61  void CompleteAdding();
62 
63  /// <summary>
64  /// Provides a consuming enumerable for items in this collection.
65  /// </summary>
66  /// <returns>An enumerable that removes and returns items from the collection</returns>
67  IEnumerable<T> GetConsumingEnumerable();
68 
69  /// <summary>
70  /// Provides a consuming enumerable for items in this collection.
71  /// </summary>
72  /// <param name="cancellationToken">A cancellation token to observer</param>
73  /// <returns>An enumerable that removes and returns items from the collection</returns>
74  IEnumerable<T> GetConsumingEnumerable(CancellationToken cancellationToken);
75  }
76 }