Jonathan Sandusky
07/12/2021, 7:49 PMCLOVIS
07/13/2021, 8:09 AMsuspend
functions. However for languages that have lambda support it's easy to provide a small function to bridge the gapJonathan Sandusky
07/14/2021, 4:15 PMCLOVIS
07/14/2021, 5:04 PMJonathan Sandusky
07/15/2021, 4:22 PMJonathan Sandusky
07/15/2021, 4:23 PMCLOVIS
07/15/2021, 8:44 PMJonathan Sandusky
07/16/2021, 7:17 PMCLOVIS
07/16/2021, 9:07 PMContinuation
hidden parameter that is added to every suspend
function, and is pretty much impossible to create from other languages.
Basically, Kotlin can use coroutines in every platform that Kotlin compiles to, but that platform cannot call suspend
functions. Most of the time when writing Kotlin, that's not an issue because you're writing code used by other Kotlin code, but if it is an issue for you, then you'll have to provide your own wrapper over your API that translates suspend functions to that language (for example using Promise
in JS). It's a shame that interop only works one way, but coroutines are just better in every way so everyone accepted it.CLOVIS
07/16/2021, 9:11 PMsuspend
keyword, that does all the compiler magic, but it is fairly bare. In a real project you'll want a library that handles all the complicated stuff (creating threads, dispatching coroutines over them, switching between threads, etc). JetBrains provides KotlinX.Coroutines, which does exactly that, but you could still use suspend functions without using KotlinX (for example, Arrow uses them for their bind
notation, the Sequence builder uses them to implement yield
, etc).CLOVIS
07/16/2021, 9:12 PM