Can Kotlin coroutines be used in production, and what does their experimental status mean?
1 Answer
UPDATE: Kotlin coroutines are no longer experimental as of Kotlin 1.3.
Kotlin coroutines can and should be used in production. That was the chief reason to officially release them in Kotlin 1.1. Having released them, the JetBrains team had committed to maintain backwards compatibility with respect to any changes that are introduced to them in the minor releases as they evolve, while allowing people to safely try them in complex production applications.
In short, the difference between “experimental” and “normal” features, is that for normal Kotlin features new stuff cannot be added in minor updates, because there is a "full compatibility" guarantee, while for experimental features new stuff can be added, but nothing can be removed (because of the backwards compatibility guarantee).
Experimental coroutines use a separate kotlin.coroutines.experimental
package name, so that when coroutines design is finalized and they move to kotlin.coroutines
package, old compiled code will not break, but will continue to work via a separate support library.
Further discussion (long-read) about why they are "experimental" and what does this mean can be found in this forum post by Andrey Breslav.
The same question applies to coroutines support libraries.
The current version of kotlinx.coroutines
is designed for production use. It is pretty well covered with tests, lots of things are already optimized, all the changes are made considering the issues of backwards compatibility with previously compiled code. It certainly does serve as a test-bed for various coroutine-based things, so there are some parts that are clearly marked as "work in progress" or "unstable" in the documentation of the corresponding functions and classes. However, by default, all the public APIs in kotlinx.coroutines
are considered to be stable and are being evolved, if needed, with appropriate migration aids.
-
5It still makes me worries when I see the highlighted warning on the function we use e.g. launch, stating
The feature "coroutines" is experimental (see more here)
and link to kotlinlang.org/docs/diagnostics/experimental-coroutines.html– ElyeJan 25, 2018 at 22:47 -
4It's a bit of a Catch-22, isn't it? How are they going to be battle-tested if nobody tries them out :) On the other hand, my experience with JetBrains' "experimental" features is miles above the experience with "production quality" releases from many other vendors. Specifically, I have had absolutely zero issues with the implementation of coroutines; the only "glitches" I saw were about some details in their treatment by the static type system, which have no repercussions on the runtime. They passed quite serious stress tests and benchmarks in Hazelcast Jet, with flying colors. Feb 6, 2018 at 12:12
-
Parts of this answer are patently wrong. The entire package is experimental, not some parts of it. Aug 15, 2018 at 23:03