But if I use any await in the task body, calling the sync version of the function produces compiler error. The compiler complains that I need to use 'await' with async functions. For example:
Ah, ok. The issue is that the async version wins out in overload resolution. The workaround is explained in SE-0296—wrap the synchronous call in a closure:
func f() async {
let f2 = {
// In a synchronous context, the non-async overload is preferred:
doSomething()
}
f2()
}