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()
|
||||
|
||||
@@ -58,6 +58,7 @@ abstract class BaseScratchCardNudgeHelper(
|
||||
|
||||
protected val scratchCardPoller: NaviApiPoller by lazy {
|
||||
NaviApiPoller(
|
||||
initialDelay = pollingConfig.initialDelay?.toLong() ?: 0,
|
||||
repeatInterval = pollingConfig.interval?.seconds ?: POLL_INTERVAL,
|
||||
numberOfIterations = pollingConfig.numOfRetries ?: MAX_POLL_COUNT,
|
||||
onPollCallback = { eventTracker.sendEvent(SCRATCH_CARD_POLLING_API_JUST_TO_BE_CALLED) },
|
||||
|
||||
Reference in New Issue
Block a user