Here is the essential problem to be solved:
You are writing code for the main thread, and (currently) you want to call a function with an asynchronous completion handler. Currently, you must write something like this:
let a = someA()
a.doSomethingWithCompletion {
result in
let b = someB(result)
print(b)
}
What we're trying to achieve is the ability to write this instead:
let a = someA()
let result = await a.doSomething
let b = someB(result)
print(b)
This is not inside an async function, because on the main thread we don't have an async starting point. If you try to force the above code to be enclosed in an async function context, then you just drive the problem back to an earlier point in the code, and eventually you hit a function context that you have no control over and can't add async
to.
I don't agree that we're committed to any concept of "effects" here, unless you think sequential execution is an effect, but if you want to acknowledge the asynchronous nature of doSomething
, it's already being done by the await
keyword.
My question is: what else is necessary and why do you think it so?