Skip to content

Commit 1fe1ab1

Browse files
authored
Fixes to resumable while (#202)
1 parent 2db01da commit 1fe1ab1

File tree

3 files changed

+29
-17
lines changed

3 files changed

+29
-17
lines changed

src/FsToolkit.ErrorHandling.IcedTasks/CancellableTaskResultCE.fs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,22 @@ module CancellableTaskResultCE =
105105
[<InlineIfLambda>] condition: unit -> bool,
106106
body: CancellableTaskResultCode<'TOverall, 'Error, unit>
107107
) : CancellableTaskResultCode<'TOverall, 'Error, unit> =
108+
let mutable keepGoing = true
109+
108110
ResumableCode.While(
109-
condition,
111+
(fun () ->
112+
keepGoing
113+
&& condition ()
114+
),
110115
CancellableTaskResultCode<_, _, _>(fun sm ->
111116
sm.Data.ThrowIfCancellationRequested()
112-
let __stack_body_fin = body.Invoke(&sm)
113117

114118
if sm.Data.IsResultError then
119+
keepGoing <- false
115120
sm.Data.MethodBuilder.SetResult sm.Data.Result
116-
false
121+
true
117122
else
118-
__stack_body_fin
123+
body.Invoke(&sm)
119124
)
120125
)
121126

src/FsToolkit.ErrorHandling.TaskResult/TaskOptionCE.fs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -519,16 +519,20 @@ type TaskOptionBuilderBase() =
519519
[<InlineIfLambda>] condition: unit -> bool,
520520
body: TaskOptionCode<'TOverall, unit>
521521
) : TaskOptionCode<'TOverall, unit> =
522+
let mutable keepGoing = true
523+
522524
ResumableCode.While(
523-
condition,
525+
(fun () ->
526+
keepGoing
527+
&& condition ()
528+
),
524529
TaskOptionCode<_, _>(fun sm ->
525-
let __stack_body_fin = body.Invoke(&sm)
526-
527530
if sm.Data.IsResultNone then
531+
keepGoing <- false
528532
sm.Data.SetResult()
529-
false
533+
true
530534
else
531-
__stack_body_fin
535+
body.Invoke(&sm)
532536
)
533537
)
534538

@@ -639,9 +643,8 @@ type TaskOptionBuilderBase() =
639643

640644
member inline this.Source(taskOption: TaskOption<'T>) : TaskOption<'T> = taskOption
641645

642-
member inline this.Source(taskOption: ValueTask<'T option>) : TaskOption<'T> = task {
643-
return! taskOption
644-
}
646+
member inline this.Source(taskOption: ValueTask<'T option>) : TaskOption<'T> =
647+
taskOption.AsTask()
645648

646649

647650
type TaskOptionBuilder() =

src/FsToolkit.ErrorHandling.TaskResult/TaskResultCE.fs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -564,16 +564,20 @@ type TaskResultBuilderBase() =
564564
[<InlineIfLambda>] condition: unit -> bool,
565565
body: TaskResultCode<'TOverall, 'Error, unit>
566566
) : TaskResultCode<'TOverall, 'Error, unit> =
567+
let mutable keepGoing = true
568+
567569
ResumableCode.While(
568-
condition,
570+
(fun () ->
571+
keepGoing
572+
&& condition ()
573+
),
569574
TaskResultCode<_, _, _>(fun sm ->
570-
let __stack_body_fin = body.Invoke(&sm)
571-
572575
if sm.Data.IsResultError then
576+
keepGoing <- false
573577
sm.Data.MethodBuilder.SetResult sm.Data.Result
574-
false
578+
true
575579
else
576-
__stack_body_fin
580+
body.Invoke(&sm)
577581
)
578582
)
579583

0 commit comments

Comments
 (0)