Skip to content

Commit

Permalink
Add special functions for binding Unit flows
Browse files Browse the repository at this point in the history
  • Loading branch information
AChep committed May 30, 2021
1 parent 9e7435c commit 0feb9d3
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions library/src/main/java/com/artemchep/bindin/BindIn.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ fun <T> LifecycleOwner.bindIn(
},
)

@JvmName("bindInUnit")
@UiThread
fun LifecycleOwner.bindIn(
flow: Flow<Unit>,
minimumLifecycleState: Lifecycle.State = DEFAULT_MIN_LIFECYCLE_STATE,
pipe: () -> Unit,
): InBinding<Unit> = bindIn(
flow = flow,
minimumLifecycleState = minimumLifecycleState,
pipe = { _: Unit ->
pipe()
},
)

/**
* The suspending [pipe] is run on the `PausingDispatcher` and hence guarantees
* that the lifecycle is in the required state. To undo the binding,
Expand Down Expand Up @@ -76,6 +90,20 @@ fun <T> LifecycleOwner.bindInSuspending(
},
)

@JvmName("bindInSuspendingUnit")
@UiThread
fun LifecycleOwner.bindInSuspending(
flow: Flow<Unit>,
minimumLifecycleState: Lifecycle.State = DEFAULT_MIN_LIFECYCLE_STATE,
pipe: suspend () -> Unit,
): InBinding<Unit> = bindInSuspending(
flow = flow,
minimumLifecycleState = minimumLifecycleState,
pipe = { _: Unit ->
pipe()
},
)

@Suppress("FunctionName")
@UiThread
private inline fun <T> LifecycleOwner._bindIn(
Expand Down

0 comments on commit 0feb9d3

Please sign in to comment.