NTP-56704 | add polling delay for rewards api (#15831)
This commit is contained in:
committed by
GitHub
parent
db76399c90
commit
8fd21046ae
@@ -19,6 +19,7 @@ import kotlinx.coroutines.flow.channelFlow
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
|
||||
class NaviApiPoller(
|
||||
private val initialDelay: Long = 0,
|
||||
private val repeatInterval: Duration,
|
||||
private val onPollCallback: () -> Unit = {},
|
||||
private val onStopPolling: () -> Unit = {},
|
||||
@@ -36,12 +37,12 @@ class NaviApiPoller(
|
||||
}
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
fun startPolling(
|
||||
suspend fun startPolling(
|
||||
onTimeout: (suspend () -> Unit)? = null,
|
||||
onPollExecute: suspend () -> Any,
|
||||
): Flow<Any> {
|
||||
delay(this.initialDelay)
|
||||
initStartPolling()
|
||||
|
||||
return channelFlow {
|
||||
while (!isClosedForSend && isPollingExternalConditionSatisfied(onTimeout)) {
|
||||
onPollCallback.invoke()
|
||||
|
||||
Reference in New Issue
Block a user