This is a minimal working example of using Kotlin coroutines. Kotlin is a neat language that offers simple, Swift style syntax while targeting the JVM, meaning it works everywhere that Java does. Kotlin's coroutines are experimental but, so far, offer a very promising approach to issues related to asynchronous programming. More information on the use and features of coroutines is available here. The syntax should be very familiar to anyone who has worked with Swift's Dispatch or async
/await
in C#.
This project builds using the Gradle Wrapper which means that there is a small build script (gradlew
or gradlew.bat
) that will download and setup the proper version of Gradle when run, and use that version in the future. For this example, no setup is required.
Run the top-level file run
. That's it. This is a tiny script that calls the Gradle Wrapper, which in turn will set up Gradle and run the provided example. In this case, we're just running this example from the Kotlin coroutine documentation, which creates 100,000 coroutines which each wait one second and then print a dot.
Run the top-level file distribute
. That's it. By default, Gradle will bundle up the required Java archives (.jar
files) and executables for Unix and Windows and compress these as .tar
and .zip
files in build/distributions
. These archives can be distributed and the executables therein used on any platform with Java available.
© 2017 Steve Richey. Shared under an MIT license. See license.md for details.