Updated on 2026-08-14
This commit is contained in:
parent
78818a6efa
commit
bd3ee9e237
33 changed files with 643 additions and 207 deletions
|
|
@ -0,0 +1,8 @@
|
|||
package com.tangem.utils.converter
|
||||
|
||||
interface TwoWayConverter<I, O> : Converter<I, O> {
|
||||
fun convertBack(value: O): I
|
||||
fun convertListBack(input: List<O>): List<I> {
|
||||
return input.map { convertBack(it) }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,10 +1,31 @@
|
|||
package com.tangem.utils.coroutines
|
||||
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
suspend fun <R> runCatching(dispatcher: CoroutineDispatcher, block: suspend () -> R): Result<R> {
|
||||
return runCatching {
|
||||
withContext(dispatcher) { block() }
|
||||
}
|
||||
}
|
||||
|
||||
class Debouncer {
|
||||
|
||||
private var debounceJob: Job? = null
|
||||
|
||||
fun debounce(
|
||||
waitMs: Long = 300L,
|
||||
coroutineScope: CoroutineScope,
|
||||
destinationFunction: () -> Unit,
|
||||
) {
|
||||
debounceJob?.cancel()
|
||||
debounceJob = coroutineScope.launch {
|
||||
delay(waitMs)
|
||||
destinationFunction.invoke()
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue