Skip to content

Latest commit

 

History

History
24 lines (21 loc) · 1.7 KB

File metadata and controls

24 lines (21 loc) · 1.7 KB

Coroutines Example

This repository contains examples of using Kotlin Coroutines for asynchronous programming in Android applications. Each code snippet demonstrates different aspects of coroutines, such as launching coroutines, working with flows, using channels for inter-coroutine communication, and more. You need to comment line other codes if you want to try a code sample.

Kotlin Coroutines provide a powerful way to manage asynchronous tasks in Android applications. They simplify asynchronous programming by allowing developers to write asynchronous code in a sequential, easy-to-understand manner.

This repository aims to demonstrate various use cases and best practices of Kotlin Coroutines through code examples.

Basics

  • Page 6: Introduction to launching coroutines with delays and using different dispatchers.
  • Page 7: Using async to perform asynchronous operations and runBlocking to wait for the result.
  • Page 8: Delaying execution within a coroutine.
  • Page 9: Launching a coroutine to update the UI thread.
  • Page 10: Performing network requests within coroutines.

Flows

  • Page 23: Creating simple flows and collecting their values.
  • Page 24: Converting collections to flows and collecting their values.
  • Page 25: Transforming emitted values using map in flows.
  • Page 26: Filtering emitted values using filter in flows.
  • Page 27: Using transform to perform complex transformations in flows.
  • Page 28: Using flowOn to change the context of flow emission.

Channels

  • Page 31: Creating and using channels for one-to-one communication between coroutines.
  • Page 32: Using channels for communication between multiple sender and receiver coroutines.
  • Page 33: Using ticker channels to emit periodic events.