@@ -373,7 +373,7 @@ asyncchecksuite "Test SafeAsyncIter":
373373 # Now, to make sure that this mechanism works, and to document its
374374 # cancellation semantics, this test shows that when the async predicate
375375 # function is cancelled, this cancellation has immediate effect, which means
376- # that `next()` (or more precisely `getNext()` in `mapFilter` function), is
376+ # that `next()` (or more precisely `getNext()` in `mapFilter` function), is
377377 # interrupted immediately. If this is the case, the the iterator be interrupted
378378 # before `next()` returns this locally captured value from the previous
379379 # iteration and this is exactly the reason why at the end of the test
@@ -404,14 +404,29 @@ asyncchecksuite "Test SafeAsyncIter":
404404
405405 expect CancelledError :
406406 for fut in iter2:
407- if i =? (await fut):
407+ without i =? (await fut), err :
408408 collected.add (i)
409- else :
410- fail ()
411409
412410 check:
413411 # We expect only values "0" and "1" to be collected
414412 # and not value "2" that - although resolved and ready to be returned -
415413 # will not be returned because of the cancellation.
416414 collected == @ [" 0" , " 1" ]
417415 iter2.finished
416+
417+ test " should allow chaining" :
418+ let
419+ iter1 = SafeAsyncIter [int ].new (0 ..< 5 )
420+ iter2 = SafeAsyncIter [int ].new (5 ..< 10 )
421+ iter3 = chain [int ](iter1, SafeAsyncIter [int ].empty, iter2)
422+
423+ var collected: seq [int ]
424+
425+ for fut in iter3:
426+ without i =? (await fut), err:
427+ fail ()
428+ collected.add (i)
429+
430+ check:
431+ iter3.finished
432+ collected == @ [0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ]
0 commit comments