Search code examples
kotlinarrow-kt

IO dispatchers VS KotlinX dispatchers inside an fx block


when using IO, in an fx block I can use continueOn with dispatchers.io() but also Dispatchers.IO or I can mix. Is there a preferred way? Is there any difference between the two?

Note: I am also using the coroutines integration to run the 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)
    }

Solution

  • There is no preferred way, and the users can choose to use one, or both together.

    While Arrow Fx's pool offers a couple of simple Executor pools similar to other functional effect libraries. These are very efficient with a functional approach.

    On the other side KotlinX's dispatcher currently offers more features such as an EventLoop, it loads the Main dispatcher through ServiceLoader and has testing support.

    I am also using the coroutines integration to run the IO

    The KotlinX integration module for Arrow Fx's IO is only meant for integration with structured concurrency CoroutineScope.