Skip to content

Commit

Permalink
Utils naming/xmldoc polish
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink committed Mar 31, 2024
1 parent ff2fd7d commit 1d1dac5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
18 changes: 7 additions & 11 deletions src/FSharp.Control.TaskSeq/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ namespace FSharp.Control

open System.Threading.Tasks
open System
open System.Diagnostics
open System.Threading

[<AutoOpen>]
module ValueTaskExtensions =
Expand All @@ -24,15 +22,15 @@ module ValueTask =
let inline ofSource taskSource version = ValueTask<bool>(taskSource, version)
let inline ofTask (task: Task<'T>) = ValueTask<'T> task

let inline ignore (vtask: ValueTask<'T>) =
let inline ignore (valueTask: ValueTask<'T>) =
// this implementation follows Stephen Toub's advice, see:
// https://github.com/dotnet/runtime/issues/31503#issuecomment-554415966
if vtask.IsCompletedSuccessfully then
if valueTask.IsCompletedSuccessfully then
// ensure any side effect executes
vtask.Result |> ignore
valueTask.Result |> ignore
ValueTask()
else
ValueTask(vtask.AsTask())
ValueTask(valueTask.AsTask())

[<Obsolete "From version 0.4.0 onward, 'ValueTask.FromResult' is deprecated in favor of 'ValueTask.fromResult'. It will be removed in an upcoming release.">]
let inline FromResult (value: 'T) = ValueTask<'T> value
Expand Down Expand Up @@ -72,14 +70,12 @@ module Async =
let inline ofTask (task: Task<'T>) = Async.AwaitTask task
let inline ofUnitTask (task: Task) = Async.AwaitTask task
let inline toTask (async: Async<'T>) = task { return! async }
let inline bind binder (task: Async<'T>) : Async<'U> = ExtraTopLevelOperators.async { return! binder task }

let inline ignore (async': Async<'T>) = async {
let! _ = async'
return ()
}
let inline ignore (async: Async<'T>) = Async.Ignore async

let inline map mapper (async: Async<'T>) : Async<'U> = ExtraTopLevelOperators.async {
let! result = async
return mapper result
}

let inline bind binder (async: Async<'T>) : Async<'U> = ExtraTopLevelOperators.async { return! binder async }
24 changes: 12 additions & 12 deletions src/FSharp.Control.TaskSeq/Utils.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ module ValueTask =

/// <summary>
/// The function <paramref name="FromResult" /> is deprecated since version 0.4.0,
/// please use <paramref name="fromSource" /> in its stead. See <see cref="T:FSharp.Control.ValueTask.fromResult" />.
/// please use <paramref name="fromResult" /> in its stead. See <see cref="T:FSharp.Control.ValueTask.fromResult" />.
/// </summary>
[<Obsolete "From version 0.4.0 onward, 'ValueTask.FromResult' is deprecated in favor of 'ValueTask.fromResult'. It will be removed in an upcoming release.">]
val inline FromResult: value: 'T -> ValueTask<'T>

/// <summary>
/// Initialized a new instance of <see cref="ValueTask" /> with an <see cref="IValueTaskSource" /> representing
/// Initializes a new instance of <see cref="ValueTask" /> with an <see cref="IValueTaskSource" />
/// representing its operation.
/// </summary>
val inline ofSource: taskSource: IValueTaskSource<bool> -> version: int16 -> ValueTask<bool>
Expand All @@ -42,15 +42,18 @@ module ValueTask =
[<Obsolete "From version 0.4.0 onward, 'ValueTask.ofIValueTaskSource' is deprecated in favor of 'ValueTask.ofSource'. It will be removed in an upcoming release.">]
val inline ofIValueTaskSource: taskSource: IValueTaskSource<bool> -> version: int16 -> ValueTask<bool>

/// Creates a ValueTask form a Task<'T>
/// Creates a ValueTask from a Task<'T>
val inline ofTask: task: Task<'T> -> ValueTask<'T>

/// Ignore a ValueTask<'T>, returns a non-generic ValueTask.
val inline ignore: vtask: ValueTask<'T> -> ValueTask
/// Convert a ValueTask<'T> into a non-generic ValueTask, ignoring the result
val inline ignore: valueTask: ValueTask<'T> -> ValueTask

module Task =

/// Convert an Async<'T> into a Task<'T>
/// Create a task from a value
val inline fromResult: value: 'U -> Task<'U>

/// Starts a running instance of an Async<'T>, represented as a Task<'T>
val inline ofAsync: async: Async<'T> -> Task<'T>

/// Convert a unit-task into a Task<unit>
Expand Down Expand Up @@ -80,9 +83,6 @@ module Task =
/// Bind a Task<'T>
val inline bind: binder: ('T -> #Task<'U>) -> task: Task<'T> -> Task<'U>

/// Create a task from a value
val inline fromResult: value: 'U -> Task<'U>

module Async =

/// Convert an Task<'T> into an Async<'T>
Expand All @@ -91,14 +91,14 @@ module Async =
/// Convert a unit-task into an Async<unit>
val inline ofUnitTask: task: Task -> Async<unit>

/// Convert a Task<'T> into an Async<'T>
/// Starts a running instance of an Async<'T>, represented as a Task<'T>
val inline toTask: async: Async<'T> -> Task<'T>

/// Convert an Async<'T> into an Async<unit>, ignoring the result
val inline ignore: async': Async<'T> -> Async<unit>
val inline ignore: async: Async<'T> -> Async<unit>

/// Map an Async<'T>
val inline map: mapper: ('T -> 'U) -> async: Async<'T> -> Async<'U>

/// Bind an Async<'T>
val inline bind: binder: (Async<'T> -> Async<'U>) -> task: Async<'T> -> Async<'U>
val inline bind: binder: (Async<'T> -> Async<'U>) -> async: Async<'T> -> Async<'U>

0 comments on commit 1d1dac5

Please sign in to comment.