Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StartAsTask -> StartImmediateAsTask #204

Merged
merged 1 commit into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions benchmarks/AsyncResultCE.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace FsToolkit.ErrorHandling.Benchmarks
namespace FsToolkit.ErrorHandling.Benchmarks

open System
open BenchmarkDotNet
Expand Down Expand Up @@ -54,22 +54,22 @@ module AsyncResultCEExtensions =
/// Method lets us transform data types into our internal representation.
/// </summary>
member inline _.Source(result: Result<_, _>) : Async<Result<_, _>> = Async.singleton result
let rec fib n =
let rec fib n =
if n < 2L then n
else fib (n - 1L) + fib (n - 2L)

let rec afib (n, level) = async {
if n < 0L then return Error "No"
elif n < 2L then
return Ok n
elif n < level then
elif n < level then
return Ok (fib n)
else
let! n2a = afib (n-2L, level) |> Async.StartChild
let! n1 = afib (n-1L, level)
let! n2 = n2a
match n1, n2 with
| Ok n1, Ok n2 ->
| Ok n1, Ok n2 ->
return Ok (n2 + n1)
| Error e, _
| _, Error e -> return Error e
Expand All @@ -81,28 +81,28 @@ module AsyncResultCEExtensions =

[<Benchmark(Baseline = true)>]
member this.afib() =
afib(10,5)
|> Async.StartAsTask
afib(10,5)
|> Async.StartImmediateAsTask

[<Benchmark>]
member this.Result_Normal_Bind_CE() =
member this.Result_Normal_Bind_CE() =
let action () = asyncResult {
let! a = Ok 10
let! b = Ok 5
let! c = afib(a, b)
return c
}
action ()
|> Async.StartAsTask
|> Async.StartImmediateAsTask


[<Benchmark>]
member this.Result_Alt_Inlined_Bind_CE () =
member this.Result_Alt_Inlined_Bind_CE () =
let action () = asyncResultInlinedIfLambda {
let! a = Ok 10
let! b = Ok 5
let! c = afib(a, b)
return c
}
action ()
|> Async.StartAsTask
|> Async.StartImmediateAsTask
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ module CancellableTaskResultCE =
}

static member inline AsCancellableTaskResult(computation: Async<'T>) =
fun ct -> Async.StartAsTask(computation, cancellationToken = ct)
fun ct -> Async.StartImmediateAsTask(computation, cancellationToken = ct)

type CancellableTaskResultBuilderBase with

Expand Down
12 changes: 6 additions & 6 deletions src/FsToolkit.ErrorHandling.TaskResult/TaskOptionCE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ module TaskOptionCE =
/// </summary>
member inline _.Source(async: Async<_ option>) : Task<_ option> =
async
|> Async.StartAsTask
|> Async.StartImmediateAsTask

/// <summary>
/// Method lets us transform data types into our internal representation.
Expand Down Expand Up @@ -268,7 +268,7 @@ module TaskOptionCE =
/// </summary>
member inline _.Source(async: Async<_ option>) : Task<_ option> =
async
|> Async.StartAsTask
|> Async.StartImmediateAsTask

/// <summary>
/// Method lets us transform data types into our internal representation.
Expand Down Expand Up @@ -360,7 +360,7 @@ module TaskOptionCEExtensions =
FSharp.Control.Tasks.Affine.task {
let! o =
a
|> Async.StartAsTask
|> Async.StartImmediateAsTask

return Some o
}
Expand Down Expand Up @@ -421,7 +421,7 @@ module TaskOptionCEExtensions =
FSharp.Control.Tasks.NonAffine.task {
let! o =
a
|> Async.StartAsTask
|> Async.StartImmediateAsTask

return Some o
}
Expand Down Expand Up @@ -639,7 +639,7 @@ type TaskOptionBuilderBase() =

member inline this.Source(computation: Async<'T option>) : TaskOption<'T> =
computation
|> Async.StartAsTask
|> Async.StartImmediateAsTask

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

Expand Down Expand Up @@ -1039,6 +1039,6 @@ module TaskOptionCEExtensionsMediumPriority =
member inline this.Source(computation: Async<'T>) : TaskOption<'T> =
computation
|> Async.map Some
|> Async.StartAsTask
|> Async.StartImmediateAsTask

#endif
2 changes: 1 addition & 1 deletion src/FsToolkit.ErrorHandling.TaskResult/TaskResult.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module TaskResult =
let inline ofAsync aAsync =
aAsync
|> Async.Catch
|> Async.StartAsTask
|> Async.StartImmediateAsTask
|> Task.map Result.ofChoice

let inline retn x =
Expand Down
12 changes: 6 additions & 6 deletions src/FsToolkit.ErrorHandling.TaskResult/TaskResultCE.fs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ module TaskResultCE =
/// </summary>
member inline _.Source(result: Async<Result<_, _>>) : Task<Result<_, _>> =
result
|> Async.StartAsTask
|> Async.StartImmediateAsTask

/// <summary>
/// Method lets us transform data types into our internal representation.
Expand Down Expand Up @@ -286,7 +286,7 @@ module TaskResultCE =
/// </summary>
member inline _.Source(result: Async<Result<_, _>>) : Task<Result<_, _>> =
result
|> Async.StartAsTask
|> Async.StartImmediateAsTask

/// <summary>
/// Method lets us transform data types into our internal representation.
Expand Down Expand Up @@ -349,7 +349,7 @@ module TaskResultCEExtensions =
FSharp.Control.Tasks.Affine.task {
let! r =
asyncComputation
|> Async.StartAsTask
|> Async.StartImmediateAsTask

return Ok r
}
Expand Down Expand Up @@ -426,7 +426,7 @@ module TaskResultCEExtensions =
FSharp.Control.Tasks.NonAffine.task {
let! r =
asyncComputation
|> Async.StartAsTask
|> Async.StartImmediateAsTask

return Ok r
}
Expand Down Expand Up @@ -695,7 +695,7 @@ type TaskResultBuilderBase() =

member inline _.Source(result: Async<Result<_, _>>) : Task<Result<_, _>> =
result
|> Async.StartAsTask
|> Async.StartImmediateAsTask

member inline _.Source(t: ValueTask<Result<_, _>>) : Task<Result<_, _>> = task { return! t }
member inline _.Source(result: Result<_, _>) : Task<Result<_, _>> = Task.singleton result
Expand Down Expand Up @@ -1064,6 +1064,6 @@ module TaskResultCEExtensionsMediumPriority =
member inline this.Source(computation: Async<'T>) : TaskResult<'T, 'Error> =
computation
|> Async.map Ok
|> Async.StartAsTask
|> Async.StartImmediateAsTask

#endif
2 changes: 1 addition & 1 deletion tests/FsToolkit.ErrorHandling.TaskResult.Tests/Expecto.fs
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ type Expect =

static member CancellationRequested(operation: Task<_>) =
Expect.CancellationRequested(Async.AwaitTask operation)
|> Async.StartAsTask
|> Async.StartImmediateAsTask
4 changes: 2 additions & 2 deletions tests/FsToolkit.ErrorHandling.TaskResult.Tests/List.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ let userId4 = Guid.NewGuid()

let notifyNewPostSuccess x =
notifyNewPostSuccess x
>> Async.StartAsTask
>> Async.StartImmediateAsTask

let notifyNewPostFailure x =
notifyNewPostFailure x
>> Async.StartAsTask
>> Async.StartImmediateAsTask

[<Tests>]
let traverseTaskResultMTests =
Expand Down
6 changes: 3 additions & 3 deletions tests/FsToolkit.ErrorHandling.TaskResult.Tests/TaskOption.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ let runTaskSync (task: Task<_>) = task.Result

let createPostSome =
createPostSome
>> Async.StartAsTask
>> Async.StartImmediateAsTask

let getFollowersSome =
getFollowersSome
>> Async.StartAsTask
>> Async.StartImmediateAsTask

let allowedToPostOptional =
allowedToPostOptional
>> Async.StartAsTask
>> Async.StartImmediateAsTask


let mapTests =
Expand Down
10 changes: 5 additions & 5 deletions tests/FsToolkit.ErrorHandling.TaskResult.Tests/TaskResult.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ let runTaskSync (task: Task<_>) = task.Result

let createPostSuccess =
createPostSuccess
>> Async.StartAsTask
>> Async.StartImmediateAsTask

let createPostFailure =
createPostFailure
>> Async.StartAsTask
>> Async.StartImmediateAsTask

let getFollowersSuccess =
getFollowersSuccess
>> Async.StartAsTask
>> Async.StartImmediateAsTask

let getFollowersFailure =
getFollowersFailure
>> Async.StartAsTask
>> Async.StartImmediateAsTask

let allowedToPost =
allowedToPost
>> Async.StartAsTask
>> Async.StartImmediateAsTask

[<Tests>]
let mapTests =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ open TestHelpers

let getUserById x =
getUserById x
|> Async.StartAsTask
|> Async.StartImmediateAsTask

let getPostById x =
getPostById x
|> Async.StartAsTask
|> Async.StartImmediateAsTask


[<Tests>]
Expand Down