Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java for Android
  • Android Studio
  • Android Kotlin
  • Kotlin
  • Flutter
  • Dart
  • Android Project
  • Android Interview
Open In App
Next Article:
Launch vs Async in Kotlin Coroutines
Next article icon

Launch vs Async in Kotlin Coroutines

Last Updated : 07 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

The Kotlin team defines coroutines as “lightweight threads”. They are sort of tasks that the actual threads can execute. Coroutines were added to Kotlin in version 1.3 and are based on established concepts from other languages. Kotlin coroutines introduce a new style of concurrency that can be used on Android to simplify async code.

The official documentation says that coroutines are lightweight threads. By lightweight, it means that creating coroutines doesn’t allocate new threads. Instead, they use predefined thread pools and smart scheduling for the purpose of which task to execute next and which tasks later.

There are mainly two functions in Kotlin to start the coroutines. 

  • launch{ }
  • async{ }

Launch Function

The launch will not block the main thread, but on the other hand, the execution of the rest part of the code will not wait for the launch result since launch is not a suspend call. Following is a Kotlin Program Using Launch:

Kotlin
// Kotlin Program For better understanding of launch fun GFG()  {   var resultOne = "Android"   var resultTwo = "Kotlin"   Log.i("Launch", "Before")   launch(Dispatchers.IO) { resultOne = function1() }   launch(Dispatchers.IO) { resultTwo = function2() }   Log.i("Launch", "After")   val resultText = resultOne + resultTwo   Log.i("Launch", resultText) }  suspend fun function1(): String  {   delay(1000L)   val message = "function1"   Log.i("Launch", message)   return message }  suspend fun function2(): String  {   delay(100L)   val message = "function2"   Log.i("Launch", message)   return message } 

 
 When you will run the code in Android IDE, the log result will be:
 

Expected log output


 

Kotlin
// pseudo kotlin code for demonstration of launch GlobalScope.launch(Dispatchers.Main)  {   // do on IO thread   fetchUserAndSaveInDatabase()  }  suspend fun fetchUserAndSaveInDatabase()  {   // fetch user from network   // save user in database   // and do not return anything } 

 
 As the fetchUserAndSaveInDatabase() does not return anything, we can use the launch to complete that task and then do something on Main Thread.
 

When to Use Launch?

Launch can be used at places where users do not want to use the returned result, which is later used in performing some other work. For example, It can be used at places involving tasks like update or changing a color, as in this case returned information would be of no use.
 

Async Function

Async is also used to start the coroutines, but it blocks the main thread at the entry point of the await() function in the program. Following is a Kotlin Program Using Async:

Kotlin
// kotlin program for demonstration of async fun GFG  {   Log.i("Async", "Before")   val resultOne = Async(Dispatchers.IO) { function1() }   val resultTwo = Async(Dispatchers.IO) { function2() }   Log.i("Async", "After")   val resultText = resultOne.await() + resultTwo.await()   Log.i("Async", resultText) }  suspend fun function1(): String  {   delay(1000L)   val message = "function1"   Log.i("Async", message)   return message }  suspend fun function2(): String  {   delay(100L)   val message = "function2"   Log.i("Async", message)   return message } 

 
 One important point to note is that Async makes both of the networks call for result1 and result2 in parallel, whereas with launch parallel function calls are not made. When you will run the code in Android IDE, the log result will be:
 

Expected log output


When to Use Async?

When making two or more network call in parallel, but you need to wait for the answers before computing the output, ie use async for results from multiple tasks that run in parallel. If you use async and do not wait for the result, it will work exactly the same as launch.
 

Table of Differences

 Below is the table of differences between Launch and Async:

Launch

Async

The launch is basically fire and forget.Async is basically performing a task and return a result.
launch{} does not return anything.async{ }, which has an await() function returns the result of the coroutine.
launch{} cannot be used when you need the parallel execution of network calls.Use async only when you need the parallel execution network calls.
Execution of other parts  of the code will not wait for the launch result since launch is not a suspend callExecution of the other parts of the code will have to wait for the result of the await() function.
It is not possible for the launch to work like async in any case or condition.If you use async and do not wait for the result, it will work exactly the same as launch.
Launch can be used at places if you don't need the result from the method called. Use async when you need the results from the multiple tasks that run in parallel. 
Example: It can be used at places involving tasks like update or changing color like fetch User And Save In Database. Example: Imagine the condition, when we have to fetch two users' data from the database by using two parallel network calls and then use them for computing some results based on their data. 


 


Next Article
Launch vs Async in Kotlin Coroutines

L

lavishgarg26
Improve
Article Tags :
  • Difference Between
  • Kotlin
  • Android

Similar Reads

    Scopes in Kotlin Coroutines
    Scope in Kotlin's coroutines can be defined as the restrictions within which the Kotlin coroutines are being executed. Scopes help to predict the lifecycle of the coroutines. Kotlin CoroutinesScope is a term well used in the referred for the interface used for defining the Scope(lifetime and context
    6 min read
    Jobs, Waiting, Cancellation in Kotlin Coroutines
    Prerequisite: Kotlin Coroutines On AndroidDispatchers in Kotlin CoroutinesSuspend Function In Kotlin Coroutines In this article, the following topics will be discussed like what are the jobs in a coroutine, how to wait for the coroutine, and how to cancel the coroutine. Whenever a new coroutine is l
    7 min read
    withContext in Kotlin Coroutines
    Prerequisite: Kotlin Coroutines on AndroidLaunch vs Async in Kotlin Coroutines It is known that async and launch are the two ways to start the coroutine. Since It is known that async is used to get the result back, & should be used only when we need the parallel execution, whereas the launch is
    3 min read
    Suspend Function In Kotlin Coroutines
    Prerequisite: Kotlin Coroutines on Android The Kotlin team defines coroutines as “lightweight threads”. They are sort of tasks that the actual threads can execute. Coroutines were added to Kotlin in version 1.3 and are based on established concepts from other languages. Kotlin coroutines introduce a
    4 min read
    runBlocking in Kotlin Coroutines with Example
    Prerequisite: Kotlin Coroutines on AndroidSuspend Function In Kotlin Coroutines As it is known that when the user calls the delay() function in any coroutine, it will not block the thread in which it is running, while the delay() function is called one can do some other operations like updating UI a
    5 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences