未验证 提交 35971aac 编写于 作者: T Tomas Grosup 提交者: GitHub

Bind of Async<> within task{} should start on the same thread (#14499)

* Bind Async within task{} should start on the same thread
The automatic versioning will cover for this with next product release.
上级 c3aacd03
......@@ -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)
......@@ -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() =
......@@ -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
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册