Skip to content
Learn Netverks

Lesson

Step 26/36 72% through track

flows-intro

Flows introduction

Last reviewed May 28, 2026 Content v20260528
Track mode
server_compiled
Means
Compiled runner
Reading
~1 min
Level
advanced

This lesson

An orientation to the Kotlin track—how the compiled playground works, core vocabulary, and what you will practice next.

You need a clear map of the Kotlin track so null safety, data classes, coroutines, and JVM interop do not feel like magic.

You will apply Flows introduction in contexts like: Network calls, database I/O, and UI state on Android and Ktor servers.

Write Kotlin in main.kt with fun main(), click Run on server—the dev runner kotlinc compiles to a JVM jar and java runs it; use println for output (requires JDK + kotlinc; LEARNING_RUNNER_ENABLED=true). Also read the interview prep blocks.

After the Java track or strong Java experience—Kotlin is designed as a better Java for JVM and Android teams.

A Flow is a cold asynchronous stream of values—like sequences for coroutines. Emit items with flow { } builders; collectors apply map, filter, and terminal operators. Requires kotlinx-coroutines locally; this lesson previews stream thinking with threads.

Cold streams

Each collector runs the flow from the start unless cached with shareIn or stateIn in real projects. Backpressure and cancellation propagate through structured concurrency.

runBlocking with flows (Gradle)

// Local only
runBlocking {
    simpleFlow().collect { println(it) }
}

In production services, collect inside a coroutineScope tied to request lifetime—not blocking threads per event.

Important interview questions and answers

  1. Q: Flow vs Sequence?
    A: Sequences are synchronous; flows can suspend between emissions and respect coroutine context and cancellation.
  2. Q: Cold vs hot stream?
    A: Cold flows start work per collector; hot streams (SharedFlow, channels) broadcast to multiple subscribers.

Self-check

  1. What library provides Flow?
  2. Does each collector restart a cold flow?

Tip: Flow is cold—collecting starts execution; compare with hot StateFlow in Android ViewModel patterns locally.

Interview prep

Cold vs hot?

Flow is cold until collected; StateFlow is hot state holder.

Dependency?

kotlinx-coroutines library on Gradle classpath.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • Flow vs Channel?
  • Cold flow?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump