Roman Elizarov — Structured concurrency

Hydra · 28K views · 2019 · 1:00:01

Open on YouTube

Programming language designSoftware architecture & designSoftware practice, open source & careerstalk

Why Stack Overflow recommends it

Stack Overflow users link it in Kotlin coroutine answers as a reference for the design ideas behind coroutine scopes, cancellation and structured concurrency.

Recommended by 2 people across 2 different months, 2019 to 2022.

What it is

A conference talk by Roman Elizarov, the lead of Kotlin's coroutine libraries, on how structured concurrency was discovered and implemented in Kotlin. He walks through the problem of tracking lifetimes of threads, tasks and coroutines, and draws a parallel to the shift from GOTO to structured programming. It was recorded at the Hydra conference.

Cited in 1 Wikipedia article, including Structured concurrency.

What people said

Recommends Alexey Soshin · 2019-10 · Stack Overflow · on “kotlin coroutines: possible without standard library?”

Can I start a coroutine using pure kotlin, without importing any libraries whatsoever (however ugly that would be)? No. All coroutine generators are inside kotlinx.coroutines library, so you'll need at least that. Now, very theoretically, you could reimplement this functionality yourself. But probably you shouldn't. How this can be done is a bit too long for a StackOverflow answer, but try invoking method of this Kotlin class from Java: class AsyncWorks { suspend fun print() { println("Hello") } } You'll see that although Kotlin method has no arguments, in Java it requires Continuation<? super Unit> . This is what suspend keyword does. It adds Continuation<T> as the last argument of our func

Recommends Abhinav Chauhan · 2022-06 · Stack Overflow · on “Does a non suspend function inside a coroutine still run on another thread?”

by using suspend keyword on a DAO function you're just saying to the room compiler that this work will happen asynchronously so there is no chance to do it on the main thread or without a coroutine that's it. When you use suspend keyword the room compiler knows that this function can only be called from a coroutine so it does not matter which dispatcher you're using room will move this operation to Dispacthers.IO internally. probably by using withContext(Dispachters.IO) according to documentation [LINK] of this method it will throw CancellationExeption if parent coroutine is cancelled, so I think the coroutine that you launched is cancelled before the insert is returned. when you don't use s

Cites Daniele Segato · 2020-09 · Stack Overflow · on “How Kotlin coroutines are better than RxKotlin?”

I know RxJava very well and I've recently switched to Kotlin Coroutines and Flow. RxKotlin is basically the same as RxJava, it just adds some syntactic sugar to make it more comfortable / idiomatic writing RxJava code in Kotlin. A "fair" comparison between RxJava and Kotlin Coroutines should include Flow in the mix and I'm gonna try to explain why here. This is gonna be a bit long but I'll try to keep it as simple as I can with examples. With RxJava you have different objects (since version 2): // 0-n events without backpressure management fun observeEventsA(): Observable<String> // 0-n events with explicit backpressure management fun observeEventsB(): Flowable<String> // exactly 1 event fun