File tree Expand file tree Collapse file tree 1 file changed +20
-5
lines changed
src/FSharp.Control.TaskSeq Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,12 @@ module ExtraTaskSeqOperators =
1111 /// A TaskSeq workflow for IAsyncEnumerable<'T> types.
1212 let taskSeq = TaskSeqBuilder()
1313
14+ [<Struct>]
15+ type AsyncEnumStatus =
16+ | BeforeAll
17+ | WithCurrent
18+ | AfterAll
19+
1420[<Struct>]
1521type Action < 'T , 'U , 'TaskU when 'TaskU :> Task < 'U >> =
1622 | CountableAction of countable_action : ( int -> 'T -> 'U )
@@ -64,15 +70,24 @@ module internal TaskSeqInternal =
6470 let singleton ( source : 'T ) =
6571 { new IAsyncEnumerable< 'T> with
6672 member _.GetAsyncEnumerator ( _ ) =
67- let mutable ended = false
73+ let mutable status = BeforeAll
6874
6975 { new IAsyncEnumerator< 'T> with
7076 member _.MoveNextAsync () =
71- let vt = ValueTask.FromResult( not ended)
72- ended <- true
73- vt
77+ match status with
78+ | BeforeAll ->
79+ status <- WithCurrent
80+ ValueTask.True
81+ | WithCurrent ->
82+ status <- AfterAll
83+ ValueTask.False
84+ | AfterAll -> ValueTask.False
85+
86+ member _.Current : 'T =
87+ match status with
88+ | WithCurrent -> source
89+ | _ -> Unchecked.defaultof< 'T>
7490
75- member _.Current : 'T = if ended then Unchecked.defaultof< 'T> else source
7691 member _.DisposeAsync () = ValueTask.CompletedTask
7792 }
7893 }
You can’t perform that action at this time.
0 commit comments