Are coroutines just syntactic sugar around completion handlers?

Are coroutines only syntactic sugar around completion blocks and completion blocks will be created under the hood? Or the concept of coroutines is much more complex and wider than just a compiler trick, as well as syntactic sugar.

+4
source share
3 answers

It’s not just syntactic sugar, not at all. Coroutines do not block Threads, they simply pause execution, so they recommend non-blocking concurrent programming .

Coroutines JVM (, ). suspend , , , . Continuations, ; " ".

. https://github.com/Kotlin/kotlin-coroutines/blob/master/kotlin-coroutines-informal.md

+4

, . , . , foo, foo , foo . Coroutines - , , , , . , :

  • ( yield ), # JavaScript. Caller coroutine, . Coroutine , yield(), .
  • Async/, # JavaScript. Caller , Future ( Task Promise) . , await(). Caller coroutine, Future , coroutine await().
  • / Go.

#, JavaScript Go, Kotlin . Kotlin suspend fun, ( kotlinx.coroutines).

+2

, ( ) Swift Concurrency. : https://spec.fm/podcasts/swift-unwrapped/84323

11:30 :

async/await .

0

Source: https://habr.com/ru/post/1685519/


All Articles