Skip to content

Lock blocks coroutine #160

@blackwiz4rd

Description

@blackwiz4rd

Hello,
I've just realized that I have a long suspending query when calling
kStoreDbIface.userInfo.get()

// commonMain
interface KStoreDbIface {
    val userInfo: KStore<UserInfoV1>
}

// android
class KStoreDb(context: Context) : KStoreDbIface {
    override val userInfo: KStore<UserInfoV1> = storeOf(
        file = Path("${context.filesDir}/user_info.json"),
        version = 1,
    )
...
}

tested only on Android.
Do you have any idea what might be happening?

My idea is that I'm calling from two coroutines the same kStoreDbIface.userInfo.get(), causing Mutex.withLock to suspend.
If any other coroutine already holds this lock, then another coroutine calling get() will suspend until the first one releases the lock.

Regards!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions