JP Sugarbroad
05/07/2025, 6:14 PMasync let
and I really want it: https://blog.yoshuawuyts.com/automatic-interleaving-of-high-level-concurrent-operations/streetsofboston
05/07/2025, 6:23 PMasync let someAsyncVar = getSomeVar()
async let otherAsyncVar = getSomeOtherVar()
followed by await [ try someAsyncVar, otherAsyncVar]
possible in kotlin with
val someAsyncVar = async { getSomeVar() }
val otherAsyncVar = async { getSomeOtherVar() }
followed by listOf(someAsyncVar, otherAsyncVar).awaitAll()
?
Or do you like the syntactic sugar of the swift code?JP Sugarbroad
05/07/2025, 6:24 PMRuckus
05/07/2025, 7:39 PMval x = async { foo() }
is more clear than async let x = foo()
JP Sugarbroad
05/07/2025, 7:39 PMRuckus
05/07/2025, 7:40 PMJP Sugarbroad
05/07/2025, 7:40 PMJP Sugarbroad
05/07/2025, 7:40 PMlet dish = Dish(ingredients: await [try veggies, tofu])
is yet another async operation, even though it doesn't say so.streetsofboston
05/07/2025, 7:40 PMawait [ try someAsyncVar, otherAsyncVar]
JP Sugarbroad
05/07/2025, 7:41 PMJP Sugarbroad
05/07/2025, 7:41 PMstreetsofboston
05/07/2025, 7:41 PMawait
in Swift vs the library function call await()
or awaitAll()
in Kotlin.JP Sugarbroad
05/07/2025, 7:42 PMstreetsofboston
05/07/2025, 7:42 PMstreetsofboston
05/07/2025, 7:43 PMRuckus
05/07/2025, 7:48 PMval dish = Dish(ingredients = listOf(veggies, tofu).awaitAll())
And can be made async easily by wrapping it in an async block like with the ingredients calls. It feels consistent.Ruckus
05/07/2025, 7:51 PMJavier
05/07/2025, 7:59 PMawaitAll(one, two, three)
Wout Werkman
05/08/2025, 9:59 AMcoroutineScope { }
block, and don't escape it. In reality this is often not the case. People frequently do things like viewModelScope.async { }
, or use other scopes that are not bound to their lexical scope. This causes many footguns.
The nice thing is that Swift enforces this in their async let
design.
But I personally prefer kotlin's approach, and I much prefer to read: launch { mySideEffect() }
over: async let _ = mySideEffect()
. And launch
is more than 10x!! as common than async
in Kotlin code.