Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Move FPAction.kt to run on IO thread by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed Apr 24, 2022
1 parent a5e0b5c commit 8eb42e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import javax.inject.Inject
class AccountsAct @Inject constructor(
private val accountDao: AccountDao
) : FPAction<Unit, List<Account>>() {

override suspend fun Unit.compose(): suspend () -> List<Account> = suspend {
io { accountDao.findAll().map { it.toDomain() } }
}
Expand Down
10 changes: 9 additions & 1 deletion ivy-fp/src/main/java/com/ivy/fp/action/FPAction.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package com.ivy.fp.action

import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

abstract class FPAction<I, O> : Action<I, O>() {
protected abstract suspend fun I.compose(): (suspend () -> O)

protected open fun dispatcher(): CoroutineDispatcher = Dispatchers.IO

override suspend fun I.willDo(): O {
return compose().invoke()
return withContext(dispatcher()) {
compose().invoke()
}
}
}

0 comments on commit 8eb42e0

Please sign in to comment.