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 d62ef74
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 5 deletions.
1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

123 changes: 123 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 d62ef74

Please sign in to comment.