Skip to content

Commit 247e430

Browse files
TheAngryByrdabelbraaksma
authored andcommitted
3 different ways to possibly implement WhileAsync
1 parent 57e7cee commit 247e430

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/FSharp.Control.TaskSeq/TaskSeq.fs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ module AsyncSeqExtensions =
398398

399399
ResumableCode.While(
400400
(fun () -> condition_res),
401-
ResumableCode<_, _>(fun sm ->
401+
TaskCode<_, _>(fun sm ->
402402
let mutable __stack_condition_fin = true
403403
let __stack_vtask = condition ()
404404

@@ -407,7 +407,7 @@ module AsyncSeqExtensions =
407407
// logInfo "at WhileAsync: returning completed task"
408408

409409
__stack_condition_fin <- true
410-
condition_res <- __stack_vtask.Result
410+
condition_res <- awaiter.GetResult()
411411
else
412412
// logInfo "at WhileAsync: awaiting non-completed task"
413413

@@ -430,16 +430,31 @@ module AsyncSeqExtensions =
430430
member inline this.For
431431
(
432432
tasksq: IAsyncEnumerable<'T>,
433-
body: 'T -> TaskCode<'TOverall, unit>
434-
) : TaskCode<'TOverall, unit> =
433+
body: 'T -> TaskCode<_, unit>
434+
) : TaskCode<_, unit> =
435+
// tasksq
436+
// |> TaskSeq.iterAsync (body >> task.Run)
437+
// |> task.ReturnFrom
438+
439+
// task.ReturnFrom <|
440+
// task {
441+
// let mutable continueWhile = true
442+
// use e = tasksq.GetAsyncEnumerator()
443+
// while continueWhile do
444+
// let! next = e.MoveNextAsync()
445+
// if next then
446+
// do! task.Run(body e.Current)
447+
// else
448+
// continueWhile <- false
449+
// }
450+
435451
TaskCode<'TOverall, unit>(fun sm ->
436452

437453
this
438454
.Using(
439455
tasksq.GetAsyncEnumerator(CancellationToken()),
440456
(fun e ->
441-
let next () = e.MoveNextAsync()
442-
this.WhileAsync(next, (fun sm -> (body e.Current).Invoke(&sm))))
457+
this.WhileAsync(e.MoveNextAsync, (fun sm -> (body e.Current).Invoke(&sm))))
443458
)
444459
.Invoke(&sm))
445460

0 commit comments

Comments
 (0)