Moreover, Kotlin's concept of suspending function ...
# announcements
v
Moreover, Kotlin's concept of suspending function provides a safer and less error-prone abstraction for asynchronous operations than futures and promises. Could someone explain why this is true?
s
Using Coroutines, you can program asynchronous code as if it is regular code, as if your code is not blocking at all and immediately returns the result. This allows you to simply use 'when' statements, 'for' loops, mutable local variables, etc, to program in a familiar sequential way. No more need for callbacks or 'map', 'flatMap', etc.
And with its Structured Concurrency, canceling asynchronous tasks is easier and it helps you prevent from 'leaking' them.
g
Structured concurrency is indifferent to suspend functions, it's way to manage resources of coroutines builders that are not suspend functions