From 8fd21046ae61de17bc1e7cbbffdf587d501b90bf Mon Sep 17 00:00:00 2001 From: Venkat Praneeth Reddy Date: Thu, 17 Apr 2025 19:27:59 +0530 Subject: [PATCH] NTP-56704 | add polling delay for rewards api (#15831) --- .../src/main/java/com/navi/common/utils/NaviApiPoller.kt | 5 +++-- .../navi/rr/scratchcard/helper/BaseScratchCardNudgeHelper.kt | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/android/navi-common/src/main/java/com/navi/common/utils/NaviApiPoller.kt b/android/navi-common/src/main/java/com/navi/common/utils/NaviApiPoller.kt index 2138c30209..2ad05870c3 100644 --- a/android/navi-common/src/main/java/com/navi/common/utils/NaviApiPoller.kt +++ b/android/navi-common/src/main/java/com/navi/common/utils/NaviApiPoller.kt @@ -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 { + delay(this.initialDelay) initStartPolling() - return channelFlow { while (!isClosedForSend && isPollingExternalConditionSatisfied(onTimeout)) { onPollCallback.invoke() diff --git a/android/navi-rr/src/main/java/com/navi/rr/scratchcard/helper/BaseScratchCardNudgeHelper.kt b/android/navi-rr/src/main/java/com/navi/rr/scratchcard/helper/BaseScratchCardNudgeHelper.kt index 018ee1b4de..19cf96c7c3 100644 --- a/android/navi-rr/src/main/java/com/navi/rr/scratchcard/helper/BaseScratchCardNudgeHelper.kt +++ b/android/navi-rr/src/main/java/com/navi/rr/scratchcard/helper/BaseScratchCardNudgeHelper.kt @@ -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) },