dimsuz
01/31/2023, 3:41 PMCoroutineScope
(hidden from outside world). And some of its methods have the form like fun startThis() = scope.launch { updateInternalState() }
, let's say it has 5 such methods.
Now, do you think it is ok to also have some methods as suspend
-methods? I.e the API would expose both launch-like and suspend-like methods and each of the latter could potentially be called from within another scope (while "Controller" has its own scope). To me this part feels a little bit weird, but maybe it's OK? I.e. I can always protect internal state access with withContext
in suspend-methods, but still I'm not sure I feel good about such an API.Sam
01/31/2023, 3:54 PMsuspend
.Sam
01/31/2023, 3:55 PMkevin.cianfarini
01/31/2023, 3:55 PMDeferred
Casey Brooks
01/31/2023, 3:57 PMCasey Brooks
01/31/2023, 3:58 PMdimsuz
01/31/2023, 3:59 PMsuspend fun deferredOperation() = withContext(mine) { ... }
?dimsuz
01/31/2023, 4:00 PMI think you’d be making a big mess for yourself if your “controller” object has a bunch of code running on different coroutineScopes.Yep, that's what I usually think. But theoretically I still can protect sensitive access by using withContext + Mutex() if needed...
dimsuz
01/31/2023, 4:01 PMThis makes the subscription the responsibility of the consumeragain, I agree and usually do it this way. (but see my comment above about "await-semantics")
Casey Brooks
01/31/2023, 4:18 PMCasey Brooks
01/31/2023, 4:21 PMdimsuz
01/31/2023, 4:59 PMCasey Brooks
01/31/2023, 5:29 PMdimsuz
01/31/2023, 10:09 PM