is there an easy way to synchronize a suspend func...
# coroutines
g
is there an easy way to synchronize a suspend function ?
a
Hi, synchronize in a way so that the function is only executed once at every given point in time? Check this out and the other sections: https://github.com/Kotlin/kotlinx.coroutines/blob/master/docs/shared-mutable-state-and-concurrency.md#actors We use actors for such cases for now
k
there's a coroutines aware`Mutex`:
Copy code
val mutex = Mutex()
suspend fun foo() = mutex.withLock { ... }
g
What is your use case? Usually better (easier to use, less error-prone) to use actor for that
g
My usecase was exactly like @andi said but I used Mutex. I will checkout actor then ­čśë Thx guys.
k
actor is overkill if mutex will suffice. actor is also deprecated/experimental API. (don't get me wrong, i really like actor, especially what the new typed actor stuff is shaping up to be, but it's overkill for some cases)