https://kotlinlang.org logo
#coroutines
Title
# coroutines
w

why

11/20/2020, 1:26 PM
Hi.. I want to use mutex.withLock{...} but it requires ‘suspend’ keyword which is a breaking change, how can I achieve the same effect (like synchronized in java) without leaking/changing my fun def? (KMP btw)
r

Robert Wijas

11/20/2020, 1:43 PM
wrap with
runBlocking
maybe?
w

why

11/20/2020, 1:43 PM
runBlocking in undefined in commonMain (KMP)
r

Robert Wijas

11/20/2020, 1:47 PM
do you support JS?
w

why

11/20/2020, 1:50 PM
yes I do, but it’s just there because I can :D
r

Robert Wijas

11/20/2020, 2:06 PM
I guess you need to either change your API or implement a
runblocking
equivalent for JS. But I’m a Kotlin newbie, so if there’s a different solution I’d love to know as well 🙂
w

why

11/20/2020, 2:09 PM
Thanks for you input, if I find anything else i’ll let you know :D
👍 1
Ok so I found a solution, I used SynchronizedObject/ReentrantLock from kotlinx.atomicfu library :D
😃 1
10 Views