@@ -51,7 +51,10 @@ internal ListingStream(Listing<T> listing)
51
51
public IDisposable Subscribe ( IObserver < T > observer )
52
52
{
53
53
if ( ! _observers . Contains ( observer ) )
54
+ {
54
55
_observers . Add ( observer ) ;
56
+ }
57
+
55
58
return new Unsubscriber ( _observers , observer ) ;
56
59
}
57
60
@@ -85,7 +88,9 @@ public Unsubscriber(ICollection<IObserver<T>> observers,
85
88
public void Dispose ( )
86
89
{
87
90
if ( _observer != null && _observers . Contains ( _observer ) )
91
+ {
88
92
_observers . Remove ( _observer ) ;
93
+ }
89
94
}
90
95
91
96
}
@@ -131,7 +136,9 @@ internal Listing(IWebAgent agent, string url, int maxLimit = -1, int limitPerReq
131
136
internal static Listing < T > Create ( IWebAgent agent , string url , int max , int perRequest )
132
137
{
133
138
if ( max > 0 && max <= perRequest )
139
+ {
134
140
perRequest = max ;
141
+ }
135
142
136
143
return new Listing < T > ( agent , url , max , perRequest ) ;
137
144
}
@@ -167,7 +174,7 @@ public IAsyncEnumerator<T> GetEnumerator(int limitPerRequest, int maximumLimit =
167
174
/// <inheritdoc/>
168
175
public IAsyncEnumerator < T > GetEnumerator ( )
169
176
{
170
- return GetEnumerator ( LimitPerRequest , MaximumLimit , IsStream ) ;
177
+ return GetEnumerator ( LimitPerRequest , MaximumLimit , IsStream ) ;
171
178
}
172
179
173
180
/// <summary>
@@ -219,9 +226,13 @@ public ListingEnumerator(Listing<T> listing, int limitPerRequest, int maximumLim
219
226
private Task FetchNextPageAsync ( )
220
227
{
221
228
if ( stream )
229
+ {
222
230
return PageForwardAsync ( ) ;
231
+ }
223
232
else
233
+ {
224
234
return PageBackAsync ( ) ;
235
+ }
225
236
}
226
237
227
238
string AppendQueryParam ( string url , string param , string value ) =>
@@ -268,7 +279,10 @@ private async Task PageBackAsync()
268
279
var json = await Listing . WebAgent . Get ( url ) . ConfigureAwait ( false ) ;
269
280
//json = json.Last();
270
281
if ( json [ "kind" ] . ValueOrDefault < string > ( ) != "Listing" )
282
+ {
271
283
throw new FormatException ( "Reddit responded with an object that is not a listing." ) ;
284
+ }
285
+
272
286
Parse ( json ) ;
273
287
}
274
288
@@ -286,7 +300,10 @@ private async Task PageForwardAsync()
286
300
url = AppendCommonParams ( url ) ;
287
301
var json = await Listing . WebAgent . Get ( url ) . ConfigureAwait ( false ) ;
288
302
if ( json [ "kind" ] . ValueOrDefault < string > ( ) != "Listing" )
303
+ {
289
304
throw new FormatException ( "Reddit responded with an object that is not a listingStream." ) ;
305
+ }
306
+
290
307
Parse ( json ) ;
291
308
}
292
309
@@ -298,7 +315,9 @@ private void Parse(JToken json)
298
315
for ( int i = 0 ; i < children . Count ; i ++ )
299
316
{
300
317
if ( ! stream )
318
+ {
301
319
things . Add ( Thing . Parse < T > ( Listing . WebAgent , children [ i ] ) ) ;
320
+ }
302
321
else
303
322
{
304
323
var kind = children [ i ] [ "kind" ] . ValueOrDefault < string > ( ) ;
@@ -312,15 +331,19 @@ private void Parse(JToken json)
312
331
{
313
332
var replyId = reply [ "data" ] [ "id" ] . ValueOrDefault < string > ( ) ;
314
333
if ( done . Contains ( replyId ) )
334
+ {
315
335
continue ;
336
+ }
316
337
317
338
things . Add ( Thing . Parse < T > ( Listing . WebAgent , reply ) ) ;
318
339
done . Add ( replyId ) ;
319
340
}
320
341
}
321
342
322
343
if ( String . IsNullOrEmpty ( id ) || done . Contains ( id ) )
344
+ {
323
345
continue ;
346
+ }
324
347
325
348
things . Add ( Thing . Parse < T > ( Listing . WebAgent , children [ i ] ) ) ;
326
349
done . Add ( id ) ;
@@ -329,7 +352,9 @@ private void Parse(JToken json)
329
352
330
353
// this doesn't really work when we're processing messages with replies.
331
354
if ( stream )
355
+ {
332
356
things . Reverse ( ) ;
357
+ }
333
358
334
359
CurrentPage = new ReadOnlyCollection < T > ( things ) ;
335
360
// Increase the total count of items returned
@@ -405,7 +430,9 @@ private async Task<bool> MoveNextForwardAsync(CancellationToken cancellationToke
405
430
tries ++ ;
406
431
407
432
if ( MaximumLimit != - 1 && Count >= MaximumLimit )
433
+ {
408
434
return false ;
435
+ }
409
436
410
437
try
411
438
{
@@ -420,7 +447,9 @@ private async Task<bool> MoveNextForwardAsync(CancellationToken cancellationToke
420
447
421
448
// the page is only populated if there are *new* items to yielded from the listing.
422
449
if ( CurrentPage . Count > 0 )
450
+ {
423
451
break ;
452
+ }
424
453
425
454
// No listings were returned in the page.
426
455
await Sleep ( tries , cancellationToken ) . ConfigureAwait ( false ) ;
@@ -439,7 +468,9 @@ private async Task Sleep(int tries, CancellationToken cancellationToken, Excepti
439
468
if ( tries > 36 )
440
469
{
441
470
if ( ex != null )
471
+ {
442
472
throw ex ;
473
+ }
443
474
}
444
475
else
445
476
{
0 commit comments