From 817a0e148459ce565f3f32092f4b61978a2f2ce7 Mon Sep 17 00:00:00 2001 From: Ganesh Jangir Date: Fri, 4 Oct 2024 12:47:45 +0200 Subject: [PATCH] back to sync flush --- DatadogCore/Sources/Core/DatadogCore.swift | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/DatadogCore/Sources/Core/DatadogCore.swift b/DatadogCore/Sources/Core/DatadogCore.swift index f6f894d69b..480bbe3701 100644 --- a/DatadogCore/Sources/Core/DatadogCore.swift +++ b/DatadogCore/Sources/Core/DatadogCore.swift @@ -159,17 +159,13 @@ internal final class DatadogCore { /// /// - Parameter trackingConsent: new consent value, which will be applied for all data collected from now on func set(trackingConsent: TrackingConsent) { - // There could be events in the queue that were collected before the consent change - // but not written to the disk yet, which must be migrated to the new consent. - // We synchronize this by reading the context because to obtain a file writer, we need to read the context. - // which is performed via CoreFeatureScope.eventWriteContext(bypassConsent:,block:) API. - contextProvider.read { _ in - if trackingConsent != self.consentPublisher.consent { - self.allStorages.forEach { - $0.migrateUnauthorizedData(toConsent: trackingConsent) - } - self.consentPublisher.consent = trackingConsent + flush() + + if trackingConsent != self.consentPublisher.consent { + self.allStorages.forEach { + $0.migrateUnauthorizedData(toConsent: trackingConsent) } + self.consentPublisher.consent = trackingConsent } }