Rob
07/08/2025, 3:45 PMMutex.withLock
but it's not reentrant. Is there a better way to achieve this?streetsofboston
07/08/2025, 3:51 PMRob
07/08/2025, 3:52 PMstreetsofboston
07/08/2025, 3:53 PMRob
07/08/2025, 3:53 PMprivate suspend fun <R> reentrantLock(block: suspend () -> R) = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
synchronized(this@MyClass) {
runBlocking {
block()
}
}
}
Rob
07/08/2025, 3:54 PMstreetsofboston
07/08/2025, 3:55 PMblock
lambda param should not be suspend
...Rob
07/08/2025, 3:56 PMRob
07/08/2025, 3:56 PMRob
07/08/2025, 3:56 PMsynchronized
doesYoussef Shoaib [MOD]
07/08/2025, 4:40 PMYoussef Shoaib [MOD]
07/08/2025, 4:43 PMRob
07/09/2025, 1:48 AMwithReentrantLock
before reading the article but thought it was too much work and just refactored it to not require it. In the comments Roman says just don't writing code that need a reentrant lock but sometimes it's unavoidable.