Skip to content

Commit 0d1cce0

Browse files
committed
Finish TaskValidation tests; fix formatting
1 parent ffa7f55 commit 0d1cce0

File tree

4 files changed

+997
-819
lines changed

4 files changed

+997
-819
lines changed

src/FsToolkit.ErrorHandling/TaskValidation.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ module TaskValidation =
9696
/// </returns>
9797
let inline orElseWith
9898
([<InlineIfLambda>] ifErrorFunc: 'errorInput list -> TaskValidation<'ok, 'errorOutput>)
99-
(validation : TaskValidation<'ok, 'errorInput>)
99+
(validation: TaskValidation<'ok, 'errorInput>)
100100
: TaskValidation<'ok, 'errorOutput> =
101101
task {
102102
let! validation = validation

src/FsToolkit.ErrorHandling/TaskValidationCE.fs

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,20 @@ type TaskValidationBuilderBase() =
6767
ResumableCode.Combine(
6868
task1,
6969
TaskValidationCode<'TOverall, 'Error, 'T>(fun sm ->
70-
if sm.Data.IsValidationError then true else task2.Invoke(&sm)
70+
if sm.Data.IsValidationError then
71+
true
72+
else
73+
task2.Invoke(&sm)
7174
)
7275
)
7376

7477

7578
/// Builds a step that executes the body while the condition predicate is true.
7679
member inline _.While
77-
([<InlineIfLambda>] condition: unit -> bool, body: TaskValidationCode<'TOverall, 'Error, unit>)
78-
: TaskValidationCode<'TOverall, 'Error, unit> =
80+
(
81+
[<InlineIfLambda>] condition: unit -> bool,
82+
body: TaskValidationCode<'TOverall, 'Error, unit>
83+
) : TaskValidationCode<'TOverall, 'Error, unit> =
7984
let mutable keepGoing = true
8085

8186
ResumableCode.While(
@@ -106,8 +111,10 @@ type TaskValidationBuilderBase() =
106111
/// Wraps a step in a try/finally. This catches exceptions both in the evaluation of the function
107112
/// to retrieve the step, and in the continuation of the step (if any).
108113
member inline _.TryFinally
109-
(body: TaskValidationCode<'TOverall, 'Error, 'T>, [<InlineIfLambda>] compensation: unit -> unit)
110-
: TaskValidationCode<'TOverall, 'Error, 'T> =
114+
(
115+
body: TaskValidationCode<'TOverall, 'Error, 'T>,
116+
[<InlineIfLambda>] compensation: unit -> unit
117+
) : TaskValidationCode<'TOverall, 'Error, 'T> =
111118

112119
ResumableCode.TryFinally(
113120
body,
@@ -127,7 +134,9 @@ type TaskValidationBuilderBase() =
127134
(fun e ->
128135
this.While(
129136
(fun () -> e.MoveNext()),
130-
TaskValidationCode<'TOverall, 'Error, unit>(fun sm -> (body e.Current).Invoke(&sm))
137+
TaskValidationCode<'TOverall, 'Error, unit>(fun sm ->
138+
(body e.Current).Invoke(&sm)
139+
)
131140
)
132141
)
133142
)
@@ -188,7 +197,9 @@ type TaskValidationBuilderBase() =
188197
)
189198

190199

191-
member inline this.Source(taskValidation: TaskValidation<'T, 'Error>) : TaskValidation<'T, 'Error> =
200+
member inline this.Source
201+
(taskValidation: TaskValidation<'T, 'Error>)
202+
: TaskValidation<'T, 'Error> =
192203
taskValidation
193204

194205

@@ -202,7 +213,9 @@ type TaskValidationBuilder() =
202213
// The executor stays constant throughout the execution, it wraps each step
203214
// of the execution in a try/with. The resumption is changed at each step
204215
// to represent the continuation of the computation.
205-
static member RunDynamic(code: TaskValidationCode<'T, 'Error, 'T>) : TaskValidation<'T, 'Error> =
216+
static member RunDynamic
217+
(code: TaskValidationCode<'T, 'Error, 'T>)
218+
: TaskValidation<'T, 'Error> =
206219
let mutable sm = TaskValidationStateMachine<'T, 'Error>()
207220

208221
let initialResumptionFunc =
@@ -285,7 +298,9 @@ type BackgroundTaskValidationBuilder() =
285298

286299
inherit TaskValidationBuilderBase()
287300

288-
static member RunDynamic(code: TaskValidationCode<'T, 'Error, 'T>) : TaskValidation<'T, 'Error> =
301+
static member RunDynamic
302+
(code: TaskValidationCode<'T, 'Error, 'T>)
303+
: TaskValidation<'T, 'Error> =
289304
// backgroundTask { .. } escapes to a background thread where necessary
290305
// See spec of ConfigureAwait(false) at https://devblogs.microsoft.com/dotnet/configureawait-faq/
291306
if
@@ -327,7 +342,9 @@ type BackgroundTaskValidationBuilder() =
327342
isNull SynchronizationContext.Current
328343
&& obj.ReferenceEquals(TaskScheduler.Current, TaskScheduler.Default)
329344
then
330-
sm.Data.MethodBuilder <- AsyncTaskValidationMethodBuilder<'T, 'Error>.Create()
345+
sm.Data.MethodBuilder <-
346+
AsyncTaskValidationMethodBuilder<'T, 'Error>.Create()
347+
331348
sm.Data.MethodBuilder.Start(&sm)
332349
sm.Data.MethodBuilder.Task
333350
else
@@ -515,7 +532,9 @@ module TaskValidationCEExtensionsHighPriority =
515532
member inline this.BindReturn(x: TaskValidation<'T, 'Error>, f) =
516533
this.Bind(x.GetAwaiter(), (fun x -> this.Return(f x)))
517534

518-
member inline _.MergeSources(t1: TaskValidation<'T, 'Error>, t2: TaskValidation<'T1, 'Error>) =
535+
member inline _.MergeSources
536+
(t1: TaskValidation<'T, 'Error>, t2: TaskValidation<'T1, 'Error>)
537+
=
519538
TaskValidation.zip t1 t2
520539

521540
member inline _.Source(s: #seq<_>) = s
@@ -546,9 +565,11 @@ module TaskValidationCEExtensionsHighPriority2 =
546565
result
547566
|> Async.StartImmediateAsTask
548567

549-
member inline _.Source(t: ValueTask<Validation<_, _>>) : Task<Validation<_, _>> = task { return! t }
568+
member inline _.Source(t: ValueTask<Validation<_, _>>) : Task<Validation<_, _>> =
569+
task { return! t }
550570

551-
member inline _.Source(result: Validation<_, _>) : Task<Validation<_, _>> = Task.singleton result
571+
member inline _.Source(result: Validation<_, _>) : Task<Validation<_, _>> =
572+
Task.singleton result
552573

553574
member inline _.Source(result: Choice<_, _>) : Task<Validation<_, _>> =
554575
result

0 commit comments

Comments
 (0)