fx 块内的 IO 调度程序 VS KotlinX 调度程序
IO dispatchers VS KotlinX dispatchers inside an fx block
使用 IO 时,在 fx 块中我可以使用 continueOn
和 dispatchers.io()
,但也可以使用 Dispatchers.IO
或者我可以混合使用。有首选方法吗?两者之间有什么区别吗?
注意:我也在使用协程集成到 运行 IO
IO.fx {
effect { _viewState.postValue(ViewState.Loading) }.bind()
continueOn(dispatchers().io()) // dispatchers from Arrow
val repositoryDto: RepositoryDto = effect { service.getRepository() }.bind()
continueOn(Dispatchers.Default) // Dispatchers from Coroutines
ViewState.Content(repositoryDto)
}
没有首选方式,用户可以选择使用一种,也可以同时使用。
虽然 Arrow Fx 的池提供了几个简单的 Executor
池,类似于其他功能效果库。这些功能方法非常有效。
另一方面,KotlinX 的调度程序目前提供更多功能,例如 EventLoop
,它通过 ServiceLoader
加载 Main
调度程序并具有测试支持。
I am also using the coroutines integration to run the IO
Arrow Fx IO 的 KotlinX 集成模块仅用于与结构化并发集成 CoroutineScope
。
使用 IO 时,在 fx 块中我可以使用 continueOn
和 dispatchers.io()
,但也可以使用 Dispatchers.IO
或者我可以混合使用。有首选方法吗?两者之间有什么区别吗?
注意:我也在使用协程集成到 运行 IO
IO.fx {
effect { _viewState.postValue(ViewState.Loading) }.bind()
continueOn(dispatchers().io()) // dispatchers from Arrow
val repositoryDto: RepositoryDto = effect { service.getRepository() }.bind()
continueOn(Dispatchers.Default) // Dispatchers from Coroutines
ViewState.Content(repositoryDto)
}
没有首选方式,用户可以选择使用一种,也可以同时使用。
虽然 Arrow Fx 的池提供了几个简单的 Executor
池,类似于其他功能效果库。这些功能方法非常有效。
另一方面,KotlinX 的调度程序目前提供更多功能,例如 EventLoop
,它通过 ServiceLoader
加载 Main
调度程序并具有测试支持。
I am also using the coroutines integration to run the IO
Arrow Fx IO 的 KotlinX 集成模块仅用于与结构化并发集成 CoroutineScope
。