https://kotlinlang.org logo
Title
f

Fred Bowker

01/06/2022, 3:26 PM
Anyone know if there are any plan for Kotlin to support async await as well as coroutines, swift uses async await and C# has had it for a long time, async await is fairly easy to understand and keeps code clean, it would be great if it came to Kotlin so we could use the same paradigm in swift and kotlin
h

hfhbd

01/06/2022, 3:30 PM
Do you mean Swift interoperability? Kotlin has
suspend
language support, which needs this https://github.com/Kotlin/kotlinx.coroutines library
f

Fred Bowker

01/06/2022, 3:33 PM
No I was meaning support for the async await keywords to allow you to run async code while writing the code in a synchronous fashion.
do {
        let result = try await getInvites(loggedOnUserId)
        invitesEnvironmentObject.replace(invites: result)
      } catch {

        showExceptionModal = true
      }
In swift I can write to call an async method
h

hfhbd

01/06/2022, 3:35 PM
In Kotlin,
async
is called
suspend
.
For
await
, you need a CoroutineScope, which is provided by the library.
e

elizarov

01/06/2022, 3:37 PM
You can get short comparison and contrast with C# approach here https://m.youtube.com/watch?v=hb0hfHVWCS0
f

Fred Bowker

01/06/2022, 3:37 PM
I can do async code through coroutines, but I think that is a different approach than how C# and Swift do async await
Ok thanks, for the link, looks like I’ll have to learn coroutines
@elizarov cheers for your work on Kotlin, I’ve been a Java dev for years but for my startup chose kotlin as I far prefer the less verbose syntax
👍 2
j

Jim

01/06/2022, 3:59 PM
Roman's KotlinConf videos detail why Kotlin uses another approach compared to C#. I highly recommend watching them to get a bigger picture.
☝️ 4
f

Fred Bowker

01/06/2022, 4:37 PM
perfect thanks for the link that clears things up