9/12/2023 0 Comments With context kotlin![]() ![]() Now, we know how the withContext and async-await differ from each other and when to use which one. ![]() withContext does not launch a coroutine and it is just a suspend function used for shifting the context of the existing coroutine.async can be used to get the result that is not possible with the launch.Both the launch and async are used to launch a coroutine.After approx 2000 milliseconds only, it will show the result as it will run both tasks in parallel. Here, we are launching two coroutines using the async, so both tasks will run in parallel. WithContext does not create a new coroutine, it only shifts the context of the existing coroutine and it's a suspend function whereas launch and async create a new coroutine and they are not suspend functions. WithContext is a suspend function through which we can do a task by providing the Dispatchers on which we want the task to be done. ![]() You can find the complete code for the implementation mentioned in this blog in the project itself. The project follows a basic MVVM Architecture for simplicity. If you have not gone through the project, you should go through it and then come back. I will be using this project for the implementation part. We will also see how the withContext and Async-await differ from each other and when to use which one. In this blog, we will learn about the withContext and Async-await in Kotlin. ![]() I am Amit Shekhar, a mentor helping developers in getting high-paying tech jobs.īefore we start, I would like to mention that, I have released a video playlist to help you crack the Android Interview: Check out Android Interview Questions and Answers. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |