Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
UnionEnumerator.cs
1using System.Collections;
2using System.Threading.Tasks;
3
4namespace Waher.Persistence
5{
11 public class UnionEnumerator<T> : IAsyncEnumerator<T>
12 where T : class
13 {
14 private readonly IAsyncEnumerator<T>[] enumerators;
15 private readonly int nrEnumerators;
16 private int position = 0;
17
23 public UnionEnumerator(params IAsyncEnumerator<T>[] Enumerators)
24 {
25 this.enumerators = Enumerators;
26 this.nrEnumerators = this.enumerators.Length;
27 }
28
32 public T Current => this.enumerators[this.position].Current;
33
37 object IEnumerator.Current => this.enumerators[this.position].Current;
38
42 public void Dispose()
43 {
44 int i;
45
46 for (i = 0; i < this.nrEnumerators; i++)
47 this.enumerators[i].Dispose();
48 }
49
54 public bool MoveNext()
55 {
56 while (this.position < this.nrEnumerators)
57 {
58 if (this.enumerators[this.position].MoveNext())
59 return true;
60
61 this.position++;
62 }
63
64 return false;
65 }
66
71 public async Task<bool> MoveNextAsync()
72 {
73 while (this.position < this.nrEnumerators)
74 {
75 if (await this.enumerators[this.position].MoveNextAsync())
76 return true;
77
78 this.position++;
79 }
80
81 return false;
82 }
83
87 public void Reset()
88 {
89 int i;
90
91 for (i = 0; i <= this.position; i++)
92 this.enumerators[i].Reset();
93
94 this.position = 0;
95 }
96 }
97}
Joins a set of enumerators into one, that enumerates the items of each consequitively.
bool MoveNext()
Moves to the next item.
void Dispose()
Disposes of the enumerator, and all embedded enumerators.
async Task< bool > MoveNextAsync()
Moves to the next item.
void Reset()
Resets the enumerator, and corresponding embedded enumerators.
UnionEnumerator(params IAsyncEnumerator< T >[] Enumerators)
Joins a set of enumerators into one, that enumerates the items of each consequitively.
Interface for asynchronous enumerators.