Native Shopify Mobile App with 20 new features
Kickstart your hyperlocal marketplace in Corona pandemic with a starter guide
Android App Development
iOS App Development
Cross Platform App Development
Hire on-demand project developers and turn your idea into working reality.
Big thanks to Webkul and his team for helping get Opencart 3.0.3.7 release ready!
Deniel Kerr
Owner and Founder. Opencart
Top Partners
In this blog, we are going to learn about how we can handle multiple coroutines in Kotlin.
When we launch coroutines in Kotlin using launch it returns a Job object as a result
We can manage that coroutine with the help of the Job object. Like it can be used to wait for the coroutine to do some work or it can be used to cancel the coroutine.
Coroutines can be controlled through the functions that are available on the Job interface. Some functions out of many that job interface offers are as follows:
join() function is a suspending function, It can be called from a coroutine or from within another suspending function. Job blocks all the threads until the coroutine finished its work.
cancel() method is used to cancel the coroutine, without waiting for it to finish its work. It can be said that it is just opposite to that of the join method.
Here we have created a fakeDownload function :
We launch a coroutine to get the job as a result. Which we can later use to join to wait for the operation to complete.
We can also use multiple joins for multiple coroutines to perform their task and wait for completion. For example :
Let’s clean up a little bit by using Collection<Job>.joinAll().
For example :
To learn more about Kotlin & Coroutines, you can also refer to this link -> Coroutines Guide
That’s done. I hope, this blog will be helpful to you.
Reference: https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/index.html
Your email address will not be published. Required fields are marked*
Name*
Email*
Save my name email and website in this browser for the next time I comment.
Be the first to comment.
We use cookies to personalize your experience. By continuing to visit this website you agree to our use of cookies. Learn more about privacy policy
When I think in getting solutions for my Ecommerce Platform, I think of Webkul. They have been such a blessing in our business. We have spent thousands of dollars in support and modules from them. We love their support team. They work very closely with us, and they always go the extra mile when we need help.
Michael Urresta
USA
India
Global
Name
Email
Enquiry or Requirement
If you have more details or questions, you can reply to the received confirmation email.