diff --git a/v4/integration/dydxStateManager/src/main/java/exchange/dydx/dydxstatemanager/protocolImplementations/AbacusThreadingImp.kt b/v4/integration/dydxStateManager/src/main/java/exchange/dydx/dydxstatemanager/protocolImplementations/AbacusThreadingImp.kt index 21d96ebc..8504c0cf 100644 --- a/v4/integration/dydxStateManager/src/main/java/exchange/dydx/dydxstatemanager/protocolImplementations/AbacusThreadingImp.kt +++ b/v4/integration/dydxStateManager/src/main/java/exchange/dydx/dydxstatemanager/protocolImplementations/AbacusThreadingImp.kt @@ -2,16 +2,19 @@ package exchange.dydx.dydxstatemanager.protocolImplementations import exchange.dydx.abacus.protocols.ThreadingProtocol import exchange.dydx.abacus.protocols.ThreadingType -import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.MainScope import kotlinx.coroutines.launch -import kotlinx.coroutines.newSingleThreadContext import kotlinx.coroutines.plus +@OptIn(ExperimentalCoroutinesApi::class) class AbacusThreadingImp : ThreadingProtocol { - private val mainScope = CoroutineScope(Dispatchers.Main) // + Job()) - private val abacusScope = CoroutineScope(newSingleThreadContext("AbacusScope")) - private val networkScope = CoroutineScope(Dispatchers.IO) + private val mainScope = MainScope() + + // Abacus runs lots of computations, but needs to be run without parallelism + private val abacusScope = MainScope() + Dispatchers.Default.limitedParallelism(1) + private val networkScope = MainScope() + Dispatchers.IO override fun async(type: ThreadingType, block: () -> Unit) { when (type) { ThreadingType.main ->