FlashKeepers

Kotlin · College · College and University

Kotlin IV: Coroutines and Flow

Coroutines, suspend functions, dispatchers, structured concurrency, channels, Flow and StateFlow.

About this set

40 basic cards for College Kotlin. Set 4 of 4 in Kotlin. It opens with "What is a suspend function in Kotlin?" and "What does the suspend keyword do?". Study it alongside the other College sets below.

40 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

What is a suspend function in Kotlin?
Show answerA function that can be paused and resumed without blocking the thread, enabling non-blocking concurrent operations.
What does the suspend keyword do?
Show answerMarks a function as suspendable, so it can call other suspend functions and be invoked only from coroutines or another suspend function.
What does the launch builder return?
Show answerA Job object representing the launched coroutine, without blocking.
What does the async builder return?
Show answerA Deferred object that represents a future result that can be awaited.
What does runBlocking do?
Show answerBlocks the current thread until the coroutine completes; used mainly in tests or main functions.
What is structured concurrency?
Show answerA paradigm where each coroutine is launched in a scope and all children must complete before the scope exits, preventing leaked coroutines.
What is a CoroutineScope?
Show answerAn interface defining the lifetime and hierarchy of coroutines within it.
What does Job represent?
Show answerThe lifecycle of a coroutine, with states like New, Active, Completing, and Completed.
What is Dispatcher.Main?
Show answerA coroutine dispatcher that runs code on the main thread, used for UI updates.
What is Dispatcher.Default?
Show answerA dispatcher for CPU-intensive work, using a thread pool sized to the number of CPU cores.
What is Dispatcher.IO?
Show answerA dispatcher optimized for blocking IO operations like network or file access.
What is Dispatcher.Unconfined?
Show answerA dispatcher that does not enforce thread affinity; generally not recommended for production.
What does withContext do?
Show answerSwitches the dispatcher for a block of code and resumes on the original dispatcher after completion.
Why is GlobalScope discouraged?
Show answerIt breaks structured concurrency because coroutines are not tied to a parent scope and can leak.
What is the difference between Job and SupervisorJob?
Show answerSupervisorJob does not propagate child failures to the parent, while Job does.

25 more cards in the app

Study this set free