Disclaimer: This article is outdated since the release of Kotlin 1.3 — You can go to this article to learn Coroutines with the new API.

Coroutines were the biggest introduction to Kotlin 1.1. They are really great because of how powerful they are, and the community is still finding out how to take the most out of them.

To put it simple, coroutines are a way to write asynchronous code sequentially. Instead of messing around with callbacks, you can write your lines of code one after the other. Some of them will have the ability to suspend the execution and wait until the result is available.

If you were a former C# developer, async/await is the closest concept. But coroutines in Kotlin are more powerful, because instead of being a specific implementation of the idea, they are a language feature that can be implemented in different ways to solve different problems.

You can write your own implementation, or use one of the several options that the Kotlin team and other independent developers have built.

You need to understand that coroutines are an experimental feature in Kotlin 1.1. This means that the implementation might change in the future, and though the old one will still be supported, you would might want to migrate to the new definition. As we’ll see later, you need to opt in for this feature, otherwise you will see a warning when you use it.

But this also means that you should take this article as an example of what you can do, not a rule of thumb. Things may change a lot in the next few months.