Skip to content

Commit

Permalink
Deprecate utils ValueTask.ofIValueTaskSource in favor of `ValueTask…
Browse files Browse the repository at this point in the history
….ofSource`
  • Loading branch information
abelbraaksma committed Nov 5, 2023
1 parent 6cee5f4 commit cd4b7ab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
13 changes: 9 additions & 4 deletions src/FSharp.Control.TaskSeq/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ module ValueTaskExtensions =
type ValueTask with

/// (Extension member) Gets a task that has already completed successfully.
static member inline CompletedTask = Unchecked.defaultof<ValueTask>
static member inline CompletedTask =
// This mimics how it is done in .NET itself
Unchecked.defaultof<ValueTask>


module ValueTask =
Expand All @@ -26,10 +28,13 @@ module ValueTask =
let inline FromResult (x: 'T) = ValueTask<'T> x

/// Creates a ValueTask with an IValueTaskSource representing the operation
let inline ofIValueTaskSource taskSource version = ValueTask<bool>(taskSource, version)
let inline ofSource taskSource version = ValueTask<bool>(taskSource, version)

[<Obsolete "From version 0.4.0 onward, 'ValueTask.ofIValueTaskSource' is deprecated in favor of 'ValueTask.ofSource'. It will be removed in an upcoming release.">]
let inline ofIValueTaskSource taskSource version = ofSource taskSource version

/// Creates a ValueTask form a Task<'T>
let inline ofTask (task: Task<'T>) = ValueTask<'T>(task)
let inline ofTask (task: Task<'T>) = ValueTask<'T> task

/// Ignore a ValueTask<'T>, returns a non-generic ValueTask.
let inline ignore (vtask: ValueTask<'T>) =
Expand Down Expand Up @@ -86,7 +91,7 @@ module Task =
}

/// Create a task from a value
let inline fromResult (value: 'U) : Task<'U> = TaskBuilder.task { return value }
let inline fromResult (value: 'U) : Task<'U> = Task.FromResult value

module Async =
/// Convert an Task<'T> into an Async<'T>
Expand Down
14 changes: 12 additions & 2 deletions src/FSharp.Control.TaskSeq/Utils.fsi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace FSharp.Control

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

Expand All @@ -22,7 +22,17 @@ module ValueTask =
/// Creates a ValueTask with the supplied result of the successful operation.
val inline FromResult: x: 'T -> ValueTask<'T>

/// Creates a ValueTask with an IValueTaskSource representing the operation
/// <summary>
/// Initialized a new instance of <see cref="ValueTask" /> with an <see cref="IValueTaskSource" /> representing
/// representing its operation.
/// </summary>
val inline ofSource: taskSource: IValueTaskSource<bool> -> version: int16 -> ValueTask<bool>

/// <summary>
/// The function <paramref name="ofIValueTaskSource" /> is deprecated since version 0.4.0,
/// please use <paramref name="ofSource" /> in its stead. See <see cref="T:FSharp.Control.ValueTask.ofSource" />.
/// </summary>
[<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>
Expand Down

0 comments on commit cd4b7ab

Please sign in to comment.