As I understand it the Swift Void type is equivalent to the void type in every other language, including Java. It does not differentiate between a function that never returns and a function that returns with no value. So yes, Kotlin does something different and (IMO) better.
Different topic… but good analogy because I think you are making a similar mistake. A suspending function is not an asynchronous function in the common use of the term “asynchronous”. So using async
would be confusing. In most other languages that use async
in the function signature the return value is some kind of promise or task indicating the code runs asynchronously (i.e. in parallel) with respect to the caller. In Kotlin, a call to a suspending function is synchronous – the caller suspends at that line of code until the call is complete.
Swift is the notable exception here, and IMO did confusingly use the async
keyword for functions that suspend and do not have some kind of Promise
return type. The developer has to deal with this at the call-site by doing either let foo = await asyncFunction()
to mark the suspension, or async let foo = asyncFunction()
to indicate that foo
is a future/deferred/promise type (and confusingly, this use of the async
keyword actually indicates parallelism, as opposed to an async
function which does not). Their documentation is similarly confusing, asserting contrary to the common use of the term that asynchronous means suspending, not parallel:
Asynchronous code can be suspended and resumed later, although only one piece of the program executes at a time.
The Kotlin reasoning for use of the suspend
key word is that suspension is the fundamental concept of concern. Furthermore, synchronous suspending calls are much more common than asynchronous calls, and thus require the least amount of ceremony.