Sr. Tech Member of Institute of Engineers (India), an Author of multiple Kotlin books, he also have certifications on Scrum. Having total 5+ years of experience he is presently working as a Sr. Software Engineer (Android) at Indus Net Technologies Pvt. Ltd. Rivu Chakraborty considers himself a Kotlin and Android enthusiast and a Kotlin evangelist. He has been using Kotlin since December 2015, so he has around 2 years' experience in Kotlin. As part of his mission to expand the use and knowledge of the Kotlin Language as much as possible, he created the KotlinKolkata User Group, one of the most active Kotlin user groups throughout the world and he is a Founder Organizer of KotlinKolkata UG. He is also an active member of GDG Kolkata and gives talks at GDG Kolkata Meetups. As Rivu believes that knowledge increases by sharing, he writes lot of tutorials at JavaCodeGeeks, AndroidHive and at his own site (http://www.rivuchk.com). Please visit his website http://www.rivuchk.com to learn more about him and to read his tutorials.
exciting feature in Kotlin are coroutines. A new way to write asynchronous, non-blocking code somewhere like the threads, but way Simpler, more efficient, and lightweight. Coroutines were added in Kotlin 1.1 and are still experimental Computation that can be suspended without blocking a thread No context switching
they execute provided block of code in the provided Coroutine context (CommonPool if not mentioned explicitly) Except that async can return a value, but launch cannot. Which one to use? Await With await function, we can suspend a coroutine and wait for a variable to get it’s value. Coroutine will not be suspended if the variable already got its value.
is the coroutine itself. As with variable (with await()), we can also wait for a job to complete. The join operator helps us wait for a job, but it must be called within another coroutine context Basically the join function joins the coroutine with the parent coroutine It was called inside, keeping their Contexts as it is. **PS runBlocking block is also a coroutine
context and runs right there. CommonPool: Represents common pool of shared threads as coroutine dispatcher for compute-intensive tasks. newSingleThreadContext: Creates new coroutine execution context with the a single thread and built-in [yield] and [delay] support. To get currently running Coroutine context just use coroutineContext inside a coroutine.
kotlin.coroutines.experimental These are shipped within kotlin-stdlib because they are related to sequences. In fact, these functions (and we can limit ourselves to buildSequence() alone here) implement generators, i.e. provide a way to cheaply build a lazy sequence. Read more at: https://kotlinlang.org/docs/reference/coroutines.html#generators-api-in- kotlincoroutines