Skip to content

observe config value as flow #71

@sproctor

Description

@sproctor

I'm sorry for the multiple issues. I've just started integrating this into an app. This one would probably be trivial to implement in my app, but it might be nice to have as part of the API.

Something like:

inline fun <reified T> Config.observe(item: Item<T>): Flow<T> =
    callbackFlow {
        send(get(item))
        val handler = afterSet { updatedItem, value ->
            if (updatedItem == item && value is T) trySend(value)
        }
        awaitClose { handler.cancel() }
    }

edit: updated code for tested/working version

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions