We should replace nearly all uses of Async.RunSynchronously in our test suites with an Async.RunImmediate that never switches to a new thread.
This makes the debugging experience much, much better, including for the old VS tests and the FSharp.COmpiler.Service.Tests.
Async.RunSynchronously jumps to a new thread if not started from a thread pool thread. This is because it's trying to avoid deadlock in REPLs and other situations, however is quite conservative. For our test suites, I believe it is going to always be safe to just run on the current thread.
typeAsyncwithstatic memberRunImmediate(computation:Async<'T>,?cancellationToken )=letcancellationToken= defaultArg cancellationToken Async.DefaultCancellationToken
letts= TaskCompletionSource<'T>()lettask= ts.Task
Async.StartWithContinuations(
computation,(fun k -> ts.SetResult k),(fun exn -> ts.SetException exn),(fun _ -> ts.SetCanceled()),
cancellationToken)
task.Result
We should replace nearly all uses of Async.RunSynchronously in our test suites with an Async.RunImmediate that never switches to a new thread.
This makes the debugging experience much, much better, including for the old VS tests and the FSharp.COmpiler.Service.Tests.
Async.RunSynchronously jumps to a new thread if not started from a thread pool thread. This is because it's trying to avoid deadlock in REPLs and other situations, however is quite conservative. For our test suites, I believe it is going to always be safe to just run on the current thread.