Skip to content

Commit

Permalink
Cleanup CompletedTask
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink committed Apr 6, 2024
1 parent 57246d6 commit b88153a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
10 changes: 2 additions & 8 deletions src/FSharp.Control.TaskSeq/Utils.fs
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
namespace FSharp.Control

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

[<AutoOpen>]
module ValueTaskExtensions =
/// Extensions for ValueTask that are not available in NetStandard 2.1, but are
/// available in .NET 5+. We put them in Extension space to mimic the behavior of NetStandard 2.1
type ValueTask with

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


module ValueTask =
let False = ValueTask<bool>()
let True = ValueTask<bool> true
Expand All @@ -38,7 +33,6 @@ 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.">]
let inline ofIValueTaskSource taskSource version = ofSource taskSource version


module Task =
let inline fromResult (value: 'U) : Task<'U> = Task.FromResult value
let inline ofAsync (async: Async<'T>) = task { return! async }
Expand Down
4 changes: 3 additions & 1 deletion src/FSharp.Control.TaskSeq/Utils.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ open System.Threading.Tasks.Sources

[<AutoOpen>]
module ValueTaskExtensions =

/// Shims back-filling .NET 5+ functionality for use on netstandard2.1
type ValueTask with

/// (Extension member) Gets a task that has already completed successfully.
/// (Extension member) Gets a ValueTask that has already completed successfully.
static member inline CompletedTask: ValueTask

module ValueTask =
Expand Down

0 comments on commit b88153a

Please sign in to comment.