Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use limitedParallelism and MainScope() in AbacusThreadingImp. #25

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down
Loading