Skip to content

Replace uses of Async.RunSynchronously in test suites with an Async.RunImmediate #11754

Description

@dsyme

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions