days
-6
-4
hours
0
-1
minutes
-4
0
seconds
-4
-3
search
Plus critical bugfixes

Kotlin 1.3 RC is out: Coroutines graduation getting closer

Eirini-Eleni Papadopoulou
kotlin
© Shutterstock /  Dooder

Another release candidate for Kotlin 1.3 has arrived with critical bugfixes in tow. This release mostly focuses on cleaning up and polishing existing features before the big 1.3 final release! We do, however, have some noteworthy changes. Let’s have a look.

Kotlin 1.3 Release Candidate is here!

This release is more of a clean-up with a bunch of bug fixes rather than new features but it does foreshadow some big news.

Coroutines will graduate to stable status in Kotlin 1.3!

So this is the time to migrate libraries using old experimental coroutines in order to get them ready by the time 1.3.0 is out. You can find detailed guidelines on the migration path for users of experimental kotlinx.coroutines library in the official blog post.

A quick trip down memory lane

Coroutines were introduced in Kotlin 1.1, which debuted earlier this year.

A coroutine is pretty much a light-weight thread that can be suspended and resumed at a later time. They are supported through suspending functions: a call to such a function can potentially suspend a coroutine. To start a new coroutine, JetBrains uses an anonymous suspending function (i.e. suspending lambdas).

But enough about how they were, let’s focus on how they changed. Some notable features include:

  • KT-16908 Support callable references to suspending functions
  • KT-18559 Serializability of all coroutine-related classes

Speaking of stuff that’s no longer experimental, you should know that the core APIs have been simplified and moved out of the experimental packages. The team is also actively working on a multiplatform version of the coroutine APIs, including iOS support through Kotlin/Native.

Let’s recap: All the packages with coroutine-related functions in Kotlin have dropped experimental from their package names, and buildSequence and buildIterator functions have moved to their permanent place in the kotlin.sequences package. However, on the language level, there is still a suspend modifier to support coroutines, and all the rules for working with coroutines remain mostly the same as they were in the experimental version, Gorbunov explained.

SEE ALSO: A first look at Kotlin 1.3: Coroutines no longer experimental

The graduated Continuation<T> interface has been simplified: there’s only one resumeWith(result: SuccessOrFailure<T>) member function.

The resume(value: T) and resumeWithException(exception: Throwable) are now defined as extensions. Don’t worry, though: only a small minority of code that defines its own coroutine builders is affected; classic examples of wrapping callbacks into suspending functions have remained mostly unchanged.

You should keep in mind that graduated coroutines use a different binary interface and are not binary-compatible with experimental coroutines. To make sure the migration is as smooth as possible, the team plans to add a compatibility layer in 1.3 and the classes for experimental coroutines will remain in the standard library, Gorbunov added. Furthermore, the compiled Kotlin/JVM code that uses experimental coroutines from 1.1 or 1.2 would still continue to work in Kotlin 1.3.

Now comes the not-so-pleasant part: the Kotlin 1.3-M1 release does not provide any support for invoking experimental suspending functions from code that is compiled with the language version 1.3. If you still want to try graduated coroutines in Kotlin 1.3-M1 with libraries that expose suspending functions in their APIs, you must use versions of these libraries that are compiled for Kotlin 1.3. Don’t worry, though: this will be fixed in no time.

The team will provide a version of kotlinx.coroutines library with x.x.x-eap13 version that is built with Kotlin 1.3 and drops experimental from its package names for every x.x.x version that we release while Kotlin 1.3 is in the preview phase.

Back to Kotlin 1.3 RC

As mentioned earlier, this RC is focused more on cleaning up things before the final release of 1.3 rather than introducing new features. However, we do have some significant changes featured in this release. Let’s have a quick look

Ktor framework – An asynchronous framework for connected applications. It features a mutliplatform HTTP client and a JVM-based HTTP server.

Code style – All new projects created in IntelliJ IDEA will use the new code style settings, which comply with the coding conventions.

Scripting –  This release brings many changes to the experimental scripting support including  the significantly reworked API.

SEE ALSO: Contracts are coming to Kotlin 1.3

Experimental serialization plugin – the compiler plugin for kotlinx.serialization is now bundled into the Kotlin compiler.

Inline classes – Kotlin reflection now handles inline class types in the signature correctly and calls box/unboxmethods automatically under the hood.

Command-line compiler – This release adds an alternative way to pass compiler arguments in a file. Instead of the -Xargfile=filename.txt form introduced in Kotlin 1.2.50, you can now pass @filename.txt as an argument to kotlinc, and it will interpret the file content as the arguments, one per line. This allows using kotlinc to compile large numbers of source files or source files with long paths.

For the full list of bug fixes and changes, you can have a look at the changelog.

Getting started

You can give Kotlin 1.3 RC a try in Maven/Gradle and IntelliJ IDEA:

Maven/Gradle: Add http://dl.bintray.com/kotlin/kotlin-eap as a repository for the build script and your projects. Use 1.3.0-rc-57 as the version number for the compiler plugin and the standard library.

IntelliJ IDEA: Go to Tools → Kotlin → Configure Kotlin Plugin Updates, select “Early Access Preview 1.3” in the Update channel drop-down list, and then click Check for updates.

You can also download the command-line compiler from the Github release page.

blqwug

Author
Eirini-Eleni Papadopoulou
Eirini-Eleni Papadopoulou is an assistant editor for JAXenter.com. Just finished her masters in Modern East Asian Studies and plans to continue with her old hobby that is computer science.