[使用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
,它通过Main
加载ServiceLoader
调度程序并具有测试支持。
我也在使用协程集成来运行IO
用于Arrow Fx IO的KotlinX集成模块仅用于与结构化并发CoroutineScope
集成。