-
Notifications
You must be signed in to change notification settings - Fork 847
Closed
Closed
Copy link
Labels
Description
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.
type Async with
static member RunImmediate (computation: Async<'T>, ?cancellationToken ) =
let cancellationToken = defaultArg cancellationToken Async.DefaultCancellationToken
let ts = TaskCompletionSource<'T>()
let task = ts.Task
Async.StartWithContinuations(
computation,
(fun k -> ts.SetResult k),
(fun exn -> ts.SetException exn),
(fun _ -> ts.SetCanceled()),
cancellationToken)
task.Result