Skip to content

Commit 550db9d

Browse files
committed
Use using declarations.
1 parent 305d381 commit 550db9d

File tree

21 files changed

+571
-630
lines changed

21 files changed

+571
-630
lines changed

Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/Catch.cs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -216,33 +216,32 @@ async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
216216

217217
foreach (var source in sources)
218218
{
219-
await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false))
219+
await using var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false);
220+
221+
error = null;
222+
223+
while (true)
220224
{
221-
error = null;
225+
TSource c;
222226

223-
while (true)
227+
try
224228
{
225-
TSource c;
226-
227-
try
228-
{
229-
if (!await e.MoveNextAsync())
230-
break;
231-
232-
c = e.Current;
233-
}
234-
catch (Exception ex)
235-
{
236-
error = ExceptionDispatchInfo.Capture(ex);
229+
if (!await e.MoveNextAsync())
237230
break;
238-
}
239231

240-
yield return c;
232+
c = e.Current;
241233
}
242-
243-
if (error == null)
234+
catch (Exception ex)
235+
{
236+
error = ExceptionDispatchInfo.Capture(ex);
244237
break;
238+
}
239+
240+
yield return c;
245241
}
242+
243+
if (error == null)
244+
break;
246245
}
247246

248247
error?.Throw();

Ix.NET/Source/System.Interactive.Async/System/Linq/Operators/DistinctUntilChanged.cs

Lines changed: 66 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -98,29 +98,28 @@ private static IAsyncEnumerable<TSource> DistinctUntilChangedCore<TSource>(IAsyn
9898

9999
async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
100100
{
101-
await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false))
101+
await using var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false);
102+
103+
if (!await e.MoveNextAsync())
102104
{
103-
if (!await e.MoveNextAsync())
104-
{
105-
yield break;
106-
}
105+
yield break;
106+
}
107107

108-
var latest = e.Current;
108+
var latest = e.Current;
109109

110-
yield return latest;
110+
yield return latest;
111111

112-
while (await e.MoveNextAsync())
113-
{
114-
var item = e.Current;
112+
while (await e.MoveNextAsync())
113+
{
114+
var item = e.Current;
115115

116-
// REVIEW: Need comparer!.Equals to satisfy nullable reference type warnings.
116+
// REVIEW: Need comparer!.Equals to satisfy nullable reference type warnings.
117117

118-
if (!comparer!.Equals(latest, item))
119-
{
120-
latest = item;
118+
if (!comparer!.Equals(latest, item))
119+
{
120+
latest = item;
121121

122-
yield return latest;
123-
}
122+
yield return latest;
124123
}
125124
}
126125
}
@@ -134,33 +133,32 @@ private static IAsyncEnumerable<TSource> DistinctUntilChangedCore<TSource, TKey>
134133

135134
async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
136135
{
137-
await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false))
136+
await using var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false);
137+
138+
if (!await e.MoveNextAsync())
138139
{
139-
if (!await e.MoveNextAsync())
140-
{
141-
yield break;
142-
}
140+
yield break;
141+
}
143142

144-
var item = e.Current;
143+
var item = e.Current;
145144

146-
var latestKey = keySelector(item);
145+
var latestKey = keySelector(item);
147146

148-
yield return item;
147+
yield return item;
149148

150-
while (await e.MoveNextAsync())
151-
{
152-
item = e.Current;
149+
while (await e.MoveNextAsync())
150+
{
151+
item = e.Current;
153152

154-
var currentKey = keySelector(item);
153+
var currentKey = keySelector(item);
155154

156-
// REVIEW: Need comparer!.Equals to satisfy nullable reference type warnings.
155+
// REVIEW: Need comparer!.Equals to satisfy nullable reference type warnings.
157156

158-
if (!comparer!.Equals(latestKey, currentKey))
159-
{
160-
latestKey = currentKey;
157+
if (!comparer!.Equals(latestKey, currentKey))
158+
{
159+
latestKey = currentKey;
161160

162-
yield return item;
163-
}
161+
yield return item;
164162
}
165163
}
166164
}
@@ -174,33 +172,32 @@ private static IAsyncEnumerable<TSource> DistinctUntilChangedCore<TSource, TKey>
174172

175173
async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
176174
{
177-
await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false))
175+
await using var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false);
176+
177+
if (!await e.MoveNextAsync())
178178
{
179-
if (!await e.MoveNextAsync())
180-
{
181-
yield break;
182-
}
179+
yield break;
180+
}
183181

184-
var item = e.Current;
182+
var item = e.Current;
185183

186-
var latestKey = await keySelector(item).ConfigureAwait(false);
184+
var latestKey = await keySelector(item).ConfigureAwait(false);
187185

188-
yield return item;
186+
yield return item;
189187

190-
while (await e.MoveNextAsync())
191-
{
192-
item = e.Current;
188+
while (await e.MoveNextAsync())
189+
{
190+
item = e.Current;
193191

194-
var currentKey = await keySelector(item).ConfigureAwait(false);
192+
var currentKey = await keySelector(item).ConfigureAwait(false);
195193

196-
// REVIEW: Need comparer!.Equals to satisfy nullable reference type warnings.
194+
// REVIEW: Need comparer!.Equals to satisfy nullable reference type warnings.
197195

198-
if (!comparer!.Equals(latestKey, currentKey))
199-
{
200-
latestKey = currentKey;
196+
if (!comparer!.Equals(latestKey, currentKey))
197+
{
198+
latestKey = currentKey;
201199

202-
yield return item;
203-
}
200+
yield return item;
204201
}
205202
}
206203
}
@@ -215,33 +212,32 @@ private static IAsyncEnumerable<TSource> DistinctUntilChangedCore<TSource, TKey>
215212

216213
async IAsyncEnumerator<TSource> Core(CancellationToken cancellationToken)
217214
{
218-
await using (var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false))
215+
await using var e = source.GetConfiguredAsyncEnumerator(cancellationToken, false);
216+
217+
if (!await e.MoveNextAsync())
219218
{
220-
if (!await e.MoveNextAsync())
221-
{
222-
yield break;
223-
}
219+
yield break;
220+
}
224221

225-
var item = e.Current;
222+
var item = e.Current;
226223

227-
var latestKey = await keySelector(item, cancellationToken).ConfigureAwait(false);
224+
var latestKey = await keySelector(item, cancellationToken).ConfigureAwait(false);
228225

229-
yield return item;
226+
yield return item;
230227

231-
while (await e.MoveNextAsync())
232-
{
233-
item = e.Current;
228+
while (await e.MoveNextAsync())
229+
{
230+
item = e.Current;
234231

235-
var currentKey = await keySelector(item, cancellationToken).ConfigureAwait(false);
232+
var currentKey = await keySelector(item, cancellationToken).ConfigureAwait(false);
236233

237-
// REVIEW: Need comparer!.Equals to satisfy nullable reference type warnings.
234+
// REVIEW: Need comparer!.Equals to satisfy nullable reference type warnings.
238235

239-
if (!comparer!.Equals(latestKey, currentKey))
240-
{
241-
latestKey = currentKey;
236+
if (!comparer!.Equals(latestKey, currentKey))
237+
{
238+
latestKey = currentKey;
242239

243-
yield return item;
244-
}
240+
yield return item;
245241
}
246242
}
247243
}

0 commit comments

Comments
 (0)