CodeGym
AI Academy
Promotion
CodeGym University
Learning
Courses
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme

Lessons

  • Reviews
  • About us
Start
Start learning
Start learning now
  • My Progress
  • Courses
  • University
  • Quest Map
  • Lessons
  • Event-driven thinking — loose coupling and the event contract

    Kotlin SELF
    Level 57, Lesson 0
    We’ll break down how to move from direct calls to publishing facts: instead of “tugging your neighbors by the sleeve”, you learn to emit an event and wire reactions through a listener list. Using the console project BudgetBuddy as an example, we build a “one → many” model, discuss why an event is a fact rather than a command, and define the contract: payload, synchrony, invocation order, error handling, and subscription management. Finally — common mistakes and how to avoid them.
    Available
  • Minimal implementation of Event<T>: listeners, subscribe, and emit

    Kotlin SELF
    Level 57, Lesson 1
    We break down a minimal event mechanism in Kotlin: what a listener is as a function of type (T) -> Unit, how to store subscribers in a MutableList, how the subscribe and emit methods work, why the type parameter T is needed, and what limitations the “simplest” implementation has (no unsubscribe, no exception handling, and no protection against list modification during dispatch).
    Available
  • Unsubscribing without pain — an unsubscribe token and the “reference” nature of lambdas

    Kotlin SELF
    Level 57, Lesson 2
    We break down why unsubscribing matters in events, why the “same” lambda is usually a different object, and how reference identity of functions works in Kotlin. We implement Event<T>, where subscribe returns an unsubscribe token ( () -> Unit) via a closure, discuss duplicate subscriptions, and careful work with function references via ::.
    Available
  • Reliable event dispatch: snapshot, try/catch, reentrancy

    Kotlin SELF
    Level 57, Lesson 3
    We break down why a naive emit() over a “live” listener list breaks in real code, how to fix it with a snapshot ( listeners.toList()), why try/ catch should wrap each handler, and what reentrancy means (nested emit() calls). In the end, we assemble a reliable Event<T>, integrate it into a mini expense tracker, and lock down the contract and common mistakes.
    Available
  • SharedFlow as an event bus: collect, replay, and the subscription lifecycle

    Kotlin SELF
    Level 57, Lesson 4
    We break down how to use SharedFlow in Kotlin as an “event bus”: what’s the difference between MutableSharedFlow and SharedFlow, how subscribing via collect works, and why “unsubscribing” is usually just Job.cancel(). We also explain the role of the replay parameter (for example, replay = 1) for “late” subscribers and show how to avoid losing a subscription because of exceptions inside the handler.
    Available
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Java Syntax
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Success Stories
  • Activity
  • Affiliate Program
Company
  • About us
  • Contacts
  • Reviews
  • Press Room
  • CodeGym for EDU
  • FAQ
  • Support
CodeGym CodeGym is an online course for learning Java programming from scratch. This course is a perfect way to master Java for beginners. It contains 1200+ tasks with instant verification and an essential scope of Java fundamentals theory. To help you succeed in education, we’ve implemented a set of motivational features: quizzes, coding projects, content about efficient learning, and a Java developer’s career.
Follow us
Interface language
English
Deutsch Español हिन्दी Français Português Polski বাংলা 简体中文 मराठी தமிழ் Italiano Bahasa Indonesia 繁體中文 Nederlands 日本語 한국어 Bulgarian Danish Hungarian Basa Jawa Malay Norwegian Romanian Swedish Telugu Thai Українська Filipino Turkish Azərbaycan Русский Vietnamese
Programmers Are Made, Not Born © 2026 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2026 CodeGym