Skip to content

Commit

Permalink
Fix SnackbarManager flow builder usage
Browse files Browse the repository at this point in the history
  • Loading branch information
alashow committed Dec 24, 2021
1 parent 6c5dc7b commit b654f93
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import javax.inject.Singleton
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.merge
import kotlinx.coroutines.flow.receiveAsFlow
import org.threeten.bp.Duration
Expand All @@ -39,11 +39,11 @@ class SnackbarManager @Inject constructor(
* or [removeCurrentError] is called (if before that) `null` will be emitted to remove
* the current error.
*/
val errors: Flow<Throwable?> = flow {
emit(null)
val errors: Flow<Throwable?> = channelFlow {
send(null)

pendingErrors.receiveAsFlow().collectLatest {
emit(it)
send(it)

// Wait for either a maxDuration timeout, or a remove signal (whichever comes first)
merge(
Expand All @@ -52,7 +52,7 @@ class SnackbarManager @Inject constructor(
).firstOrNull()

// Remove the error
emit(null)
send(null)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ import tm.alashow.ui.simpleClickable
import tm.alashow.ui.theme.AppTheme
import tm.alashow.ui.theme.Orange

private const val DRAGGABLE_ITEM_PREFIX = "draggable_"

@Composable
fun EditPlaylist(
viewModel: EditPlaylistViewModel = hiltViewModel(),
Expand Down

0 comments on commit b654f93

Please sign in to comment.