Skip to content

Commit

Permalink
Use limitedParallelism and MainScope() in AbacusThreadingImp.
Browse files Browse the repository at this point in the history
  • Loading branch information
prashanDYDX committed Mar 13, 2024
1 parent 9a5ff0a commit 3fc6da5
Showing 1 changed file with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ 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 ->
Expand Down

0 comments on commit 3fc6da5

Please sign in to comment.