Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.onesignal.core.internal.operations.impl

import com.onesignal.common.threading.OSPrimaryCoroutineScope
import com.onesignal.common.threading.WaiterWithValue
import com.onesignal.core.internal.config.ConfigModelStore
import com.onesignal.core.internal.operations.ExecutionResult
Expand Down Expand Up @@ -102,14 +103,23 @@ internal class OperationRepo(
}
}

/**
* Enqueuing will be performed in a designate coroutine and may not be added instantly.
* This is to prevent direct enqueuing from the main thread that may cause a deadlock if loading
* is still in process.
*
* If the enqueuing needs to be suspended, use enqueueAndWait() instead.
*/
override fun enqueue(
operation: Operation,
flush: Boolean,
) {
Logging.log(LogLevel.DEBUG, "OperationRepo.enqueue(operation: $operation, flush: $flush)")

operation.id = UUID.randomUUID().toString()
internalEnqueue(OperationQueueItem(operation, bucket = enqueueIntoBucket), flush, true)
OSPrimaryCoroutineScope.execute {
internalEnqueue(OperationQueueItem(operation, bucket = enqueueIntoBucket), flush, true)
}
}

override suspend fun enqueueAndWait(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.onesignal.session.internal.session.impl

import com.onesignal.common.threading.OSPrimaryCoroutineScope
import com.onesignal.common.threading.suspendifyOnThread
import com.onesignal.core.internal.config.ConfigModelStore
import com.onesignal.core.internal.operations.IOperationRepo
Expand Down Expand Up @@ -41,10 +40,7 @@ internal class SessionListener(
}

override fun onSessionStarted() {
// enqueue the operation in background
OSPrimaryCoroutineScope.execute {
_operationRepo.enqueue(TrackSessionStartOperation(_configModelStore.model.appId, _identityModelStore.model.onesignalId), true)
}
_operationRepo.enqueue(TrackSessionStartOperation(_configModelStore.model.appId, _identityModelStore.model.onesignalId), true)
}

override fun onSessionActive() {
Expand All @@ -58,12 +54,9 @@ internal class SessionListener(
Logging.error("SessionListener.onSessionEnded sending duration of $durationInSeconds seconds")
}

// enqueue the operation in background
OSPrimaryCoroutineScope.execute {
_operationRepo.enqueue(
TrackSessionEndOperation(_configModelStore.model.appId, _identityModelStore.model.onesignalId, durationInSeconds),
)
}
_operationRepo.enqueue(
TrackSessionEndOperation(_configModelStore.model.appId, _identityModelStore.model.onesignalId, durationInSeconds),
)

suspendifyOnThread {
_outcomeEventsController.sendSessionEndOutcomeEvent(durationInSeconds)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.onesignal.user.internal.service

import com.onesignal.common.IDManager
import com.onesignal.common.threading.OSPrimaryCoroutineScope
import com.onesignal.core.internal.application.IApplicationService
import com.onesignal.core.internal.config.ConfigModelStore
import com.onesignal.core.internal.operations.IOperationRepo
Expand Down Expand Up @@ -29,14 +28,12 @@ class UserRefreshService(
return
}

OSPrimaryCoroutineScope.execute {
_operationRepo.enqueue(
RefreshUserOperation(
_configModelStore.model.appId,
_identityModelStore.model.onesignalId,
),
)
}
_operationRepo.enqueue(
RefreshUserOperation(
_configModelStore.model.appId,
_identityModelStore.model.onesignalId,
),
)
}

override fun start() = _sessionService.subscribe(this)
Expand Down
Loading