Skip to content

Commit fb17a51

Browse files
Code after 'Converting Flows to SharedFlows with shareIn' lecture
1 parent 677728d commit fb17a51

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

app/src/main/java/com/lukaslechner/coroutineusecasesonandroid/usecases/flow/usecase4/FlowUseCase4ViewModel.kt

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package com.lukaslechner.coroutineusecasesonandroid.usecases.flow.usecase4
22

3+
import androidx.lifecycle.viewModelScope
34
import com.lukaslechner.coroutineusecasesonandroid.base.BaseViewModel
4-
import kotlinx.coroutines.flow.Flow
5-
import kotlinx.coroutines.flow.map
6-
import kotlinx.coroutines.flow.onCompletion
7-
import kotlinx.coroutines.flow.onStart
5+
import kotlinx.coroutines.flow.*
86
import timber.log.Timber
97

108
class FlowUseCase4ViewModel(
@@ -21,5 +19,8 @@ class FlowUseCase4ViewModel(
2119
}
2220
.onCompletion {
2321
Timber.tag("Flow").d("Flow has completed.")
24-
}
22+
}.shareIn(
23+
scope = viewModelScope,
24+
started = SharingStarted.WhileSubscribed()
25+
)
2526
}

0 commit comments

Comments
 (0)