Kotlin协程将如何使用Project Loom?

huangapple go评论71阅读模式
英文:

How Kotlin coroutines will use Project Loom?

问题

现在,Kotlin协程是在没有JVM帮助的情况下实现的。它不使用类似于绿色(虚拟)线程的东西。您可以在此处阅读有关协程实现的详细信息 - https://github.com/Kotlin/KEEP/blob/master/proposals/coroutines.md#implementation-details

在不久的将来(比如1-2年内),项目Loom(JVM中的绿色线程实现)将会发布。您可以在此处阅读有关其详细信息 - http://cr.openjdk.java.net/~rpressler/loom/loom/sol1_part1.html

那么,Kotlin会将这些虚拟线程用作编译后端吗?还是有一些原因,导致这是不可能的?我谈论的是具有所需版本的JVM目标(很明显,我们需要Android的自己实现)。

实际上,还有一个更一般的问题。当Project Loom发布时,我们是否真的需要Kotlin协程呢?

英文:

Right now, Kotlin coroutines are implemented without help of JVM. It does not use something like green (virtual) threads. You can read about implementation of coroutines here - https://github.com/Kotlin/KEEP/blob/master/proposals/coroutines.md#implementation-details

In the near future (like, 1-2 year), project Loom (implementation of green threads in JVM) will be released. You can read details about it here - http://cr.openjdk.java.net/~rpressler/loom/loom/sol1_part1.html

So, will Kotlin use these virtual threads as compilation backend? Or there are some reasons, why it is not possible? I talk about JVM target with needed version (it is obvious, that we need own implementation for android).

Actually, there is more general question. Do we really need Kotlin coroutines, when Project Loom will be released?

答案1

得分: 6

根据Roman Elizarov在他的演讲中所概述的,将会与Project Loom进行互操作

至于协程的需求,你必须认识到Kotlin是一种多平台语言,这意味着协程必须在所有平台上工作,包括浏览器和本机代码。

即使他们在JVM上使用Project Loom,API也必须保持一致,因为相同的代码将被编译到所有平台。

英文:

As Roman Elizarov outlined in his talk there will be interoperation with Project Loom.

As for the need for coroutines, you have to realize that Kotlin is a multiplatform language which means that coroutines have to work on all platforms, including the browser and native code.

Even if they will use Project Loom on the JVM the API has to stay consistent, since the same code will be compiled to all platforms.

huangapple
  • 本文由 发表于 2020年10月13日 13:23:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/64329005.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定