Skip to content
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
2 changes: 1 addition & 1 deletion src/FSharp.Control.TaskSeq/TaskExtensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module TaskExtensions =
TaskCode<'TOverall, unit>(fun sm ->
this
.Using(
source.GetAsyncEnumerator(CancellationToken()),
source.GetAsyncEnumerator CancellationToken.None,
(fun e ->
this.WhileAsync(
// __debugPoint is only available from FSharp.Core 6.0.4
Expand Down
6 changes: 3 additions & 3 deletions src/FSharp.Control.TaskSeq/TaskSeq.fs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type TaskSeq private () =

static member toList(source: TaskSeq<'T>) = [
Internal.checkNonNull (nameof source) source
let e = source.GetAsyncEnumerator(CancellationToken())
let e = source.GetAsyncEnumerator CancellationToken.None

try
while (let vt = e.MoveNextAsync() in if vt.IsCompleted then vt.Result else vt.AsTask().Result) do
Expand All @@ -51,7 +51,7 @@ type TaskSeq private () =

static member toArray(source: TaskSeq<'T>) = [|
Internal.checkNonNull (nameof source) source
let e = source.GetAsyncEnumerator(CancellationToken())
let e = source.GetAsyncEnumerator CancellationToken.None

try
while (let vt = e.MoveNextAsync() in if vt.IsCompleted then vt.Result else vt.AsTask().Result) do
Expand All @@ -65,7 +65,7 @@ type TaskSeq private () =

seq {

let e = source.GetAsyncEnumerator(CancellationToken())
let e = source.GetAsyncEnumerator CancellationToken.None

try
while (let vt = e.MoveNextAsync() in if vt.IsCompleted then vt.Result else vt.AsTask().Result) do
Expand Down
40 changes: 20 additions & 20 deletions src/FSharp.Control.TaskSeq/TaskSeqInternal.fs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module internal TaskSeqInternal =
checkNonNull (nameof source) source

task {
use e = source.GetAsyncEnumerator(CancellationToken())
use e = source.GetAsyncEnumerator CancellationToken.None
let! step = e.MoveNextAsync()
return not step
}
Expand Down Expand Up @@ -107,7 +107,7 @@ module internal TaskSeqInternal =

task {

use e = source.GetAsyncEnumerator(CancellationToken())
use e = source.GetAsyncEnumerator CancellationToken.None
let mutable go = true
let mutable i = 0
let! step = e.MoveNextAsync()
Expand Down Expand Up @@ -146,7 +146,7 @@ module internal TaskSeqInternal =

task {

use e = source.GetAsyncEnumerator(CancellationToken())
use e = source.GetAsyncEnumerator CancellationToken.None
let mutable go = true
let mutable i = 0
let! step = e.MoveNextAsync()
Expand All @@ -164,7 +164,7 @@ module internal TaskSeqInternal =
checkNonNull (nameof source) source

task {
use e = source.GetAsyncEnumerator(CancellationToken())
use e = source.GetAsyncEnumerator CancellationToken.None

match! e.MoveNextAsync() with
| true ->
Expand Down Expand Up @@ -223,7 +223,7 @@ module internal TaskSeqInternal =
checkNonNull (nameof source) source

task {
use e = source.GetAsyncEnumerator(CancellationToken())
use e = source.GetAsyncEnumerator CancellationToken.None
let mutable go = true
let! step = e.MoveNextAsync()
go <- step
Expand Down Expand Up @@ -267,7 +267,7 @@ module internal TaskSeqInternal =
checkNonNull (nameof source) source

task {
use e = source.GetAsyncEnumerator(CancellationToken())
use e = source.GetAsyncEnumerator CancellationToken.None
let mutable go = true
let mutable result = initial
let! step = e.MoveNextAsync()
Expand Down Expand Up @@ -338,8 +338,8 @@ module internal TaskSeqInternal =
checkNonNull (nameof source2) source2

taskSeq {
use e1 = source1.GetAsyncEnumerator(CancellationToken())
use e2 = source2.GetAsyncEnumerator(CancellationToken())
use e1 = source1.GetAsyncEnumerator CancellationToken.None
use e2 = source2.GetAsyncEnumerator CancellationToken.None
let mutable go = true
let! step1 = e1.MoveNextAsync()
let! step2 = e2.MoveNextAsync()
Expand Down Expand Up @@ -390,7 +390,7 @@ module internal TaskSeqInternal =
checkNonNull (nameof source) source

task {
use e = source.GetAsyncEnumerator(CancellationToken())
use e = source.GetAsyncEnumerator CancellationToken.None
let mutable go = true
let mutable last = ValueNone
let! step = e.MoveNextAsync()
Expand All @@ -410,7 +410,7 @@ module internal TaskSeqInternal =
checkNonNull (nameof source) source

task {
use e = source.GetAsyncEnumerator(CancellationToken())
use e = source.GetAsyncEnumerator CancellationToken.None

match! e.MoveNextAsync() with
| true -> return Some e.Current
Expand All @@ -421,7 +421,7 @@ module internal TaskSeqInternal =
checkNonNull (nameof source) source

task {
use e = source.GetAsyncEnumerator(CancellationToken())
use e = source.GetAsyncEnumerator CancellationToken.None

match! e.MoveNextAsync() with
| false -> return None
Expand Down Expand Up @@ -449,7 +449,7 @@ module internal TaskSeqInternal =
// to prevent side effects hitting unnecessarily
return None
else
use e = source.GetAsyncEnumerator(CancellationToken())
use e = source.GetAsyncEnumerator CancellationToken.None
let mutable go = true
let mutable idx = 0
let mutable foundItem = None
Expand All @@ -472,7 +472,7 @@ module internal TaskSeqInternal =
checkNonNull (nameof source) source

task {
use e = source.GetAsyncEnumerator(CancellationToken())
use e = source.GetAsyncEnumerator CancellationToken.None

let mutable go = true
let mutable foundItem = None
Expand Down Expand Up @@ -507,7 +507,7 @@ module internal TaskSeqInternal =
checkNonNull (nameof source) source

task {
use e = source.GetAsyncEnumerator(CancellationToken())
use e = source.GetAsyncEnumerator CancellationToken.None

let mutable go = true
let mutable foundItem = None
Expand Down Expand Up @@ -546,7 +546,7 @@ module internal TaskSeqInternal =
checkNonNull (nameof source) source

task {
use e = source.GetAsyncEnumerator(CancellationToken())
use e = source.GetAsyncEnumerator CancellationToken.None

let mutable go = true
let mutable isFound = false
Expand Down Expand Up @@ -617,7 +617,7 @@ module internal TaskSeqInternal =
checkNonNull (nameof source) source

taskSeq {
use e = source.GetAsyncEnumerator(CancellationToken())
use e = source.GetAsyncEnumerator CancellationToken.None
let! step = e.MoveNextAsync()
let mutable more = step

Expand Down Expand Up @@ -725,14 +725,14 @@ module internal TaskSeqInternal =
checkNonNull (nameof itemsToExclude) itemsToExclude

taskSeq {
use e = source.GetAsyncEnumerator(CancellationToken())
use e = source.GetAsyncEnumerator CancellationToken.None
let mutable go = true
let! step = e.MoveNextAsync()
go <- step

if step then
// only create hashset by the time we actually start iterating
use hashSet = new ConcurrentHashSet<_>(CancellationToken())
use hashSet = new ConcurrentHashSet<_>(CancellationToken.None)
do! hashSet.AddManyAsync itemsToExclude

while go do
Expand All @@ -753,14 +753,14 @@ module internal TaskSeqInternal =
checkNonNull (nameof itemsToExclude) itemsToExclude

taskSeq {
use e = source.GetAsyncEnumerator(CancellationToken())
use e = source.GetAsyncEnumerator CancellationToken.None
let mutable go = true
let! step = e.MoveNextAsync()
go <- step

if step then
// only create hashset by the time we actually start iterating
use hashSet = new ConcurrentHashSet<_>(CancellationToken())
use hashSet = new ConcurrentHashSet<_>(CancellationToken.None)
do hashSet.AddMany itemsToExclude

while go do
Expand Down
57 changes: 10 additions & 47 deletions src/FSharp.Control.TaskSeq/Utils.fs
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,12 @@ module ValueTaskExtensions =


module ValueTask =
/// A successfully completed ValueTask of boolean that has the value false.
let False = ValueTask<bool>()

/// A successfully completed ValueTask of boolean that has the value true.
let True = ValueTask<bool> true

/// Creates a ValueTask with the supplied result of the successful operation.
let inline fromResult (x: 'T) = ValueTask<'T> x

[<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 (x: 'T) = ValueTask<'T> x

/// Creates a ValueTask with an IValueTaskSource representing the operation
let inline fromResult (value: 'T) = ValueTask<'T> value
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

/// Ignore a ValueTask<'T>, returns a non-generic ValueTask.
let inline ignore (vtask: ValueTask<'T>) =
// this implementation follows Stephen Toub's advice, see:
// https://github.com/dotnet/runtime/issues/31503#issuecomment-554415966
Expand All @@ -50,29 +34,22 @@ module ValueTask =
else
ValueTask(vtask.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

[<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 =
/// Convert an Async<'T> into a Task<'T>
let inline fromResult (value: 'U) : Task<'U> = Task.FromResult value
let inline ofAsync (async: Async<'T>) = task { return! async }

/// Convert a unit-task into a Task<unit>
let inline ofTask (task': Task) = task { do! task' }

/// Convert a non-task function into a task-returning function
let inline apply (func: _ -> _) = func >> Task.FromResult

/// Convert a Task<'T> into an Async<'T>
let inline toAsync (task: Task<'T>) = Async.AwaitTask task

/// Convert a Task<'T> into a ValueTask<'T>
let inline toValueTask (task: Task<'T>) = ValueTask<'T> task

/// <summary>
/// Convert a ValueTask&lt;'T> to a Task&lt;'T>. To use a non-generic ValueTask,
/// consider using: <paramref name="myValueTask |> Task.ofValueTask |> Task.ofTask" />.
/// </summary>
let inline ofValueTask (valueTask: ValueTask<'T>) = task { return! valueTask }

/// Convert a Task<'T> into a non-generic Task, ignoring the result
let inline ignore (task: Task<'T>) =
TaskBuilder.task {
// ensure the task is awaited
Expand All @@ -81,42 +58,28 @@ module Task =
}
:> Task

/// Map a Task<'T>
let inline map mapper (task: Task<'T>) : Task<'U> = TaskBuilder.task {
let! result = task
return mapper result
}

/// Bind a Task<'T>
let inline bind binder (task: Task<'T>) : Task<'U> = TaskBuilder.task {
let! t = task
return! binder t
}

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

module Async =
/// Convert an Task<'T> into an Async<'T>
let inline ofTask (task: Task<'T>) = Async.AwaitTask task

/// Convert a unit-task into an Async<unit>
let inline ofUnitTask (task: Task) = Async.AwaitTask task

/// Convert a Task<'T> into an Async<'T>
let inline toTask (async: Async<'T>) = task { return! async }
let inline bind binder (task: Async<'T>) : Async<'U> = ExtraTopLevelOperators.async { return! binder task }

/// Convert an Async<'T> into an Async<unit>, ignoring the result
let inline ignore (async': Async<'T>) = async {
let! _ = async'
return ()
}

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

/// Bind an Async<'T>
let inline bind binder (task: Async<'T>) : Async<'U> = ExtraTopLevelOperators.async { return! binder task }
4 changes: 2 additions & 2 deletions src/FSharp.Control.TaskSeq/Utils.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ module ValueTask =
val True: ValueTask<bool>

/// Creates a ValueTask with the supplied result of the successful operation.
val inline fromResult: x: 'T -> ValueTask<'T>
val inline fromResult: value: 'T -> ValueTask<'T>

/// <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" />.
/// </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: x: 'T -> ValueTask<'T>
val inline FromResult: value: 'T -> ValueTask<'T>

/// <summary>
/// Initialized a new instance of <see cref="ValueTask" /> with an <see cref="IValueTaskSource" /> representing
Expand Down