A collection of interactive Kotlin notebooks demonstrating coroutines concepts and patterns using JetBrains Kotlin Notebook.
This repository contains hands-on examples and tutorials for learning Kotlin coroutines through interactive notebooks. Each notebook focuses on specific coroutines concepts with practical, runnable code examples.
- basics.ipynb - Fundamental coroutine patterns including launch, async/await, structured concurrency, cancellation, and Flow basics
- 101_kotlin_coroutines.ipynb - Comprehensive introduction to Kotlin coroutines
- cancellation_basics.ipynb - Deep dive into coroutine cancellation mechanisms
- exceptions.ipynb - Exception handling patterns in coroutines
- flows.ipynb - Advanced Flow operations and patterns
- supervisor_job_and_scope.ipynb - SupervisorJob and scope management
- Basic Coroutines: launch,runBlocking,async/await
- Structured Concurrency: coroutineScope, parent-child relationships
- Cancellation: Explicit cancellation, timeouts, cleanup
- Context Switching: withContext,Dispatchers
- Flow: Cold streams, operators, collection
- Exception Handling: Error propagation, structured exception handling
- Supervision: SupervisorJob, fault tolerance
- JetBrains IntelliJ IDEA or JetBrains DataSpell with Kotlin Notebook support
- Kotlin 1.8+
- kotlinx-coroutines-core 1.8.1+ (automatically managed via @file:DependsOn)
- 
Clone the repository: git clone https://github.com/smithjustinn84-netizen/notebooks.git cd notebooks
- 
Open in JetBrains IDE: - Open the project in IntelliJ IDEA or DataSpell
- Navigate to the Coroutines/directory
- Open any .ipynbfile to start learning
 
- 
Run the notebooks: - Execute cells individually to see coroutines in action
- Modify examples to experiment with different patterns
- Dependencies are automatically resolved via @file:DependsOn
 
For beginners, we recommend following this order:
- basics.ipynb - Start here for fundamental concepts
- 101_kotlin_coroutines.ipynb - Comprehensive overview
- cancellation_basics.ipynb - Understanding cancellation
- exceptions.ipynb - Error handling patterns
- flows.ipynb - Reactive streams with Flow
- supervisor_job_and_scope.ipynb - Advanced scope management
Each notebook includes:
- β Runnable code examples with real output
- β Detailed explanations of coroutine concepts
- β Timing measurements to understand concurrency benefits
- β Exception handling demonstrations
- β Best practices and common patterns
Feel free to:
- Add new notebook examples
- Improve existing explanations
- Fix any issues you encounter
- Suggest new coroutines topics to cover
- All notebooks use runBlockingfor demo purposes in a notebook environment
- In production apps, prefer structured concurrency with proper scope management
- Examples include timing measurements to demonstrate concurrent execution
- Dependencies are managed automatically via notebook annotations
Happy Learning! π Explore the world of asynchronous programming with Kotlin coroutines through these interactive examples.