asad.awadia
07/19/2019, 6:15 PMwithoutclass
07/19/2019, 6:17 PMDominaezzz
07/19/2019, 6:28 PMkotlinx.coroutines
provides an async/await mechanism.asad.awadia
07/19/2019, 6:31 PMwithoutclass
07/19/2019, 6:32 PMDominaezzz
07/19/2019, 6:35 PMsuspend
not async/await.withoutclass
07/19/2019, 6:36 PMDominaezzz
07/19/2019, 6:37 PMasad.awadia
07/19/2019, 6:37 PMwithoutclass
07/19/2019, 6:38 PMitnoles
07/19/2019, 6:39 PMwithoutclass
07/19/2019, 6:41 PMbj0
07/19/2019, 7:11 PMbdawg.io
07/19/2019, 8:21 PMasync { ... }
and then explicitly await()
on them. Kotlin suspend function are written to look like regular code instead of shifting how you write code to use asynchronous programming. With regular code, a function is invoked and it either returns a value (or absence of a value, ie `Unit`/`null`) or throws an exception. With suspend functions it either returns a value or throws an exception. With regular code, if you want to run two things concurrently, launch two threads and call the code. With suspending code, launch two coroutines and call the code. But just as you did with regular code, you were explicit about doing things concurrently. The opposite of C#asad.awadia
07/19/2019, 8:22 PMDominaezzz
07/19/2019, 8:22 PMbdawg.io
07/19/2019, 8:23 PMitnoles
07/19/2019, 8:26 PMDominaezzz
07/19/2019, 8:26 PMitnoles
07/19/2019, 8:27 PMbdawg.io
07/19/2019, 8:33 PMDefault
and IO
share threads, it's just about the total pool size available to them. If you want your code to run at its best, you need to better understand of what you're telling your code to do (which is what all the presentations/articles that talk about the dispatchers are trying to achieve)Default
OR IO
for everything, but there's a cost for not caringitnoles
07/19/2019, 8:39 PMjw
07/20/2019, 1:07 AMKotlin async is definitely concurrent - if you launch two - they are both happening simultaneouslyThis is not strictly true. The dispatcher may be single threaded which would not produce concurrent work.