本文介绍了可以“实验" Kotlin协程可用于生产?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在生产中使用Kotlin协程吗?它们的实验状态是什么意思?

Can Kotlin coroutines be used in production, and what does their experimental status mean?

推荐答案

更新:从Kotlin 1.3开始,Kotlin协程不再具有实验性.

UPDATE: Kotlin coroutines are no longer experimental as of Kotlin 1.3.

Kotlin协程可以并且应该在生产中使用.这是在Kotlin 1.1中正式发布它们的主要原因.在发布它们之后,JetBrains团队致力于保持向后兼容性,以适应次版本中随着它们的发展而引入的任何更改,同时允许人们在复杂的生产应用程序中安全地进行尝试.

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.

简而言之,实验性"功能与正常"功能之间的区别在于,对于正常的Kotlin功能,由于具有完全兼容性"保证,因此不能在次要更新中添加新功能,而对于实验性功能,则可以添加新功能可以添加,但不能删除任何内容(因为向后兼容保证).

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).

实验协程使用单独的kotlin.coroutines.experimental程序包名称,因此当协程设计最终确定并移至kotlin.coroutines程序包时,旧的编译代码不会中断,但会通过单独的支持库继续工作.

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.

有关它们为何具有实验性"及其含义的进一步讨论(长期阅读)可以在以下论坛帖子,作者:安德烈·布雷斯拉夫(Andrey Breslav).

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.

kotlinx.coroutines的当前版本是供生产使用的.它涵盖了相当多的测试,已经对许多事情进行了优化,所有更改都考虑到了与先前编译的代码的向后兼容性问题.它确实可以用作各种基于协程的事物的试验台,因此在相应功能和类的文档中,有些部分被明确标记为进行中"或不稳定".但是,默认情况下,kotlinx.coroutines中的所有公共API都被认为是稳定的,并在需要时借助适当的迁移工具进行了改进.

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.

这篇关于可以“实验" Kotlin协程可用于生产?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 04:04