Updated on 2026-08-14
This commit is contained in:
parent
e381fafeb8
commit
7cb4b57fe9
21 changed files with 556 additions and 230 deletions
|
|
@ -2,6 +2,7 @@ package com.tangem.domain.core.flow
|
|||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.firstOrNull
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
|
||||
/**
|
||||
* [Flow] supplier
|
||||
|
|
@ -16,8 +17,14 @@ interface FlowSupplier<Params : Any, Data : Any> {
|
|||
/** Supply [Flow] by [params] */
|
||||
operator fun invoke(params: Params): Flow<Data>
|
||||
|
||||
/** Get first [Data] by [params] or null if [Flow] is empty */
|
||||
suspend fun getSyncOrNull(params: Params): Data? {
|
||||
return invoke(params).firstOrNull()
|
||||
/** Synchronously get first value or null from [Flow] within [timeMillis] */
|
||||
suspend fun getSyncOrNull(params: Params, timeMillis: Long? = null): Data? {
|
||||
val block = suspend { invoke(params).firstOrNull() }
|
||||
|
||||
return if (timeMillis == null) {
|
||||
block()
|
||||
} else {
|
||||
withTimeoutOrNull(timeMillis) { block() }
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue