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
4 changes: 2 additions & 2 deletions src/FSharp.Core/tasks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ module MediumPriority =
computation: Async<'TResult1>,
continuation: ('TResult1 -> TaskCode<'TOverall, 'TResult2>)
) : TaskCode<'TOverall, 'TResult2> =
this.Bind(Async.StartAsTask computation, continuation)
this.Bind(Async.StartImmediateAsTask computation, continuation)

member inline this.ReturnFrom(computation: Async<'T>) : TaskCode<'T, 'T> =
this.ReturnFrom(Async.StartAsTask computation)
this.ReturnFrom(Async.StartImmediateAsTask computation)
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,22 @@ type Basics() =
let result = t.Result
require (result = 8) "something weird happened"

[<Fact>]
member _.testAsyncsMixedWithTasks_ShouldNotSwitchContext() =
let t = task {
let a = Thread.CurrentThread.ManagedThreadId
let! b = async {
return Thread.CurrentThread.ManagedThreadId
}
let c = Thread.CurrentThread.ManagedThreadId
return $"Before: {a}, in async: {b}, after async: {c}"
}
let d = Thread.CurrentThread.ManagedThreadId
let actual = $"{t.Result}, after task: {d}"

require (actual = $"Before: {d}, in async: {d}, after async: {d}, after task: {d}") actual


[<Fact>]
// no need to call this, we just want to check that it compiles w/o warnings
member _.testDefaultInferenceForReturnFrom() =
Expand Down Expand Up @@ -1390,5 +1406,4 @@ module Issue12184f =
// The overload resolution for Bind commits to 'Task' via SRTP pattern since the type annotation is available
let! result = t
return result
}

}