mcpiroman
12/10/2021, 5:20 PMNick Allen
12/10/2021, 6:03 PMatomic.loop
from kotlinx.atomicfu
.
If the synchronized
block is used for very fine grained synchronization such that blocking is insignificant if it even does happen, then I see no issue with using that from a coroutine. Don't suspend inside the block.
You can use runBlocking
to run coroutines (like Mutex
) from a non-suspending context. Only use this from places where blocking is expected and do not call if the code is running on a dispatcher so don't use runBlocking
from <http://Dispatchers.IO|Dispatchers.IO>
. Avoid this if you can.