Created
July 4, 2023 09:05
-
-
Save KwabenBerko/885d030e2fe8e3185644ac37000b307d to your computer and use it in GitHub Desktop.
Mutex Enabled Component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MutexEnabledComponent: Component { | |
private val mutex = Mutex() | |
var refreshesCount: Int = 0 | |
private set | |
override suspend fun refresh() { | |
if (!mutex.isLocked){ | |
mutex.withLock { | |
delay(1L) // Delay to simulate a long running operation | |
refreshesCount++ | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment