在界面中声明最后的乐趣
我正在Kotlin编写一个合作的multithreading引擎。 我试图写一个接口,如下所示:
interface Processor { var suspendAction: (Continuation) -> Unit inline suspend fun yield() = suspendCoroutine(suspendAction) suspend fun process(inbox: Inbox) = Unit }
yield()
是我想提供给所有这个接口的实现者的服务。 由于每个虚拟呼叫站点代表了内联的障碍,并且由于每个进入suspend fun
入口都有其代价,出于性能的原因,我需要这个函数是final
,但是Kotlin不允许我这样做。 我发现一个解决方法将yield()
转换为扩展的乐趣:
inline suspend fun Processor.yield() = suspendCoroutine(suspendAction)
我想问一下,这样的用例是否会激励Kotlin语言设计师在interface
final fun
。
请注意,与典型的等待IO暂停方案不同,此处的yield()
发生在CPU密集型热点线程上。
- AAR / JAR不会使用Android Studio 3.0 Canary 7生成
- 通过kotlin传递的parcelable数组正在发射最后一个项目
- kotlin android – 用Builder模式和Java 8 lambda定制对话框
- 图像存在,不为空,但我得到一个NullPointerExceptionexception
- 如何使用界面android在适配器中创建onclick事件?
- Kotlin-非单例类的单个实例?
- Kotlin:我们可以在Kotlin中使用@订阅EventBus(GreenRobot)吗?
- Android Studio(Kotlin)GsonBuilder.registerTypeAdapter()给出2个错误
- android java / kotlin recyclerview项目不可见