Skip to content

Commit 05af635

Browse files
committed
merge fix-6
2 parents d2e3dc9 + 9744c13 commit 05af635

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

src/FSharp.Control.AsyncSeq/AsyncSeq.fs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,11 @@ module AsyncSeq =
207207
if box resource <> null then resource.Dispose())
208208

209209
member x.For(seq:seq<'T>, action:'T -> AsyncSeq<'TResult>) =
210-
let enum = seq.GetEnumerator()
211-
x.TryFinally(x.While((fun () -> enum.MoveNext()), x.Delay(fun () ->
212-
action enum.Current)), (fun () ->
213-
if enum <> null then enum.Dispose() ))
210+
x.Delay(fun () ->
211+
let enum = seq.GetEnumerator()
212+
x.TryFinally(x.While((fun () -> enum.MoveNext()), x.Delay(fun () ->
213+
action enum.Current)), (fun () ->
214+
if enum <> null then enum.Dispose() )))
214215

215216
member x.For (seq:AsyncSeq<'T>, action:'T -> AsyncSeq<'TResult>) =
216217
collect action seq

tests/FSharp.Control.AsyncSeq.Tests/AsyncSeqTests.fs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,12 @@ let ``AsyncSeq.getIterator should work``() =
383383
| Some _ -> Assert.Fail("expected None")
384384

385385

386+
387+
[<Test>]
388+
let ``asyncSeq.For should delay``() =
389+
let (s:seq<int>) =
390+
{ new System.Collections.Generic.IEnumerable<int> with
391+
member x.GetEnumerator() = failwith "fail"
392+
interface System.Collections.IEnumerable with
393+
member x.GetEnumerator() = failwith "fail" }
394+
Assert.DoesNotThrow(fun _ -> asyncSeq.For(s, (fun v -> AsyncSeq.empty)) |> ignore)

0 commit comments

Comments
 (0)