Tgo1014
11/27/2024, 12:42 PMDefault
dispatcher. What’s the best way to force who uses this do that? Is it actually a bad thing to enforce this? Should it have a param like val dispatcher: CoroutineDispatcher = Dispatcher.Default
? Am I looking at this problem with the wrong lens? 🤔Sam
11/27/2024, 12:43 PMwithContext(Dispatchers.Default)
Tgo1014
11/27/2024, 12:43 PMDmitry Khalanskiy [JB]
11/27/2024, 12:47 PMdelay
call there, for example, then sure, a test dispatcher would be beneficial (does your operation run any user-supplied code?). Likewise, if your operation doesn't follow structured concurrency and runs in something like GlobalScope
, it's certainly worth it to make the CoroutineScope
injectable. If you don't see a reason for anyone to realistically want to launch your code in something other than Dispatchers.Default
, then there's probably no reason to introduce a parameter.Tgo1014
11/27/2024, 12:49 PMdelay
and all the operations on the tree are just executed by methods inside the class, so there isn’t any user-supplied code.
So I think in this case it’s indeed a good idea to go with the code wrapped in withContext(Dispatchers.Default)
.
Thanks for both inputs! 😄kevin.cianfarini
11/27/2024, 1:30 PMTgo1014
11/27/2024, 1:31 PMkevin.cianfarini
11/27/2024, 1:32 PMTgo1014
11/27/2024, 1:34 PMkevin.cianfarini
11/27/2024, 1:35 PMMain
that causes a group of issues which are really annoying since that dispatcher isn't available for tests. Default is so it's mostly fine.Michael Paus
11/27/2024, 2:18 PMwasmJs
target.Tgo1014
11/27/2024, 2:28 PM