Skip to content

Creating callbackFlow / flow as an instance and reusing it in multiple places #1897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Varsha-29 opened this issue Apr 1, 2020 · 1 comment

Comments

@Varsha-29
Copy link

Similar to channels and broadcast channels, can flows also be instantiated and reused at multiple places?

General usage of creating flows is wrapping the logic to emit the data inside flow's body and is returned.
Snippet :

fun listenToDataChanges() : Flow<T>
{
return flow {
            dataSource.querySomeInfo()?.consumeEach { 
                data->
                if (someCondition) {
                    emit(data)
                }
            }
        }
}

Everytime listenToDataChanges() is called, a new flow instance is created and multiple subscriptions would be made. Instead is it possible to create and reuse the instance to avoid multiple subscriptions?

@elizarov
Copy link
Contributor

elizarov commented Apr 2, 2020

This is planned to be provided via some-kind of share operator in the future. Please, follow #1716

@elizarov elizarov closed this as completed Apr 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants