Skip to content

Commit b98a7ca

Browse files
feat: force flush tick
1 parent 0193057 commit b98a7ca

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

sdk/src/main/java/ly/count/android/sdk/ConnectionQueue.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,6 +887,15 @@ void ensureExecutor() {
887887
* Should only be called if SDK is initialized
888888
*/
889889
public void tick() {
890+
tick(false);
891+
}
892+
893+
/**
894+
* This function blocks caller until RQ flushes, so be cautious when using it.
895+
*
896+
* @param forceFlushRQ if true, will block until RQ is fully flushed
897+
*/
898+
public void tick(boolean forceFlushRQ) {
890899
//todo enable later
891900
//assert storageProvider != null;
892901
if (backoff_.get()) {
@@ -906,8 +915,17 @@ public void tick() {
906915

907916
if (!rqEmpty && (connectionProcessorFuture_ == null || cpDoneIfOngoing)) {
908917
L.d("[ConnectionQueue] tick, Starting ConnectionProcessor");
909-
ensureExecutor();
910-
connectionProcessorFuture_ = executor_.submit(createConnectionProcessor());
918+
Runnable cp = createConnectionProcessor();
919+
if (forceFlushRQ) {
920+
try {
921+
cp.run();
922+
} catch (Exception e) {
923+
L.e("[ConnectionQueue] tick, forceFlushRQ encountered an error: " + e.getMessage());
924+
}
925+
} else {
926+
ensureExecutor();
927+
connectionProcessorFuture_ = executor_.submit(cp);
928+
}
911929
}
912930
}
913931

sdk/src/main/java/ly/count/android/sdk/RequestQueueProvider.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ interface RequestQueueProvider {
5252

5353
void tick();
5454

55+
void tick(boolean forceFlushRQ);
56+
5557
ConnectionProcessor createConnectionProcessor();
5658

5759
String prepareRemoteConfigRequestLegacy(@Nullable String keysInclude, @Nullable String keysExclude, @NonNull String preparedMetrics);

0 commit comments

Comments
 (0)