可以“实验"吗?Kotlin 协程可以在生产中使用吗? [英] Can "experimental" Kotlin coroutines be used in production?

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

问题描述

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

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

推荐答案

UPDATE:Kotlin 协程从 Kotlin 1.3 开始不再是实验性的.

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 协程可以在生产中使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆