Skip to content
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

How to emit data to kotlin flow #1448

Closed
iTanChi opened this issue Aug 19, 2019 · 3 comments
Closed

How to emit data to kotlin flow #1448

iTanChi opened this issue Aug 19, 2019 · 3 comments

Comments

@iTanChi
Copy link

iTanChi commented Aug 19, 2019

How can I emit new data to an existing Kotlin Flow? Currently I can only do it inside the flow block like this:

val data: Flow<Boolean> = flow {
    emit(newData)
}

I want to do something like:

fun someMethod() {
    data.emit(newData)
}

I can do it if I use Android LiveData:

val data: LiveData<Boolean> = MutableLiveData()

fun someMethod() {
    data.postValue(newData) // data.value = newData
}

or something likes it in RxJava2 with onNext event

@ashdavies
Copy link

Afaik Flow is designed to be a self contained, replayable, cold stream, so emission from outside of it's own scope wouldn't be part of the contract. I think what you're looking for is a Channel.

@iTanChi
Copy link
Author

iTanChi commented Aug 19, 2019

Thanks @ashdavies

@iTanChi iTanChi closed this as completed Aug 19, 2019
@elizarov
Copy link
Contributor

The Flow analogue of LiveData is being developed in PR #1354. Right now you can use ConflatedBroadcastChannel.

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

3 participants