diff --git a/Sources/MixpanelInstance.swift b/Sources/MixpanelInstance.swift index bda85a8f..ea0dcae0 100644 --- a/Sources/MixpanelInstance.swift +++ b/Sources/MixpanelInstance.swift @@ -909,7 +909,7 @@ extension MixpanelInstance { } func unarchive() { - self.readWriteLock.write { + let didCreateIdentity = self.readWriteLock.write { optOutStatus = MixpanelPersistence.loadOptOutStatusFlag(instanceName: self.name) superProperties = MixpanelPersistence.loadSuperProperties(instanceName: self.name) timedEvents = MixpanelPersistence.loadTimedEvents(instanceName: self.name) @@ -927,6 +927,14 @@ extension MixpanelInstance { distinctId = addPrefixToDeviceId(deviceId: anonymousId) hadPersistedDistinctId = true userId = nil + return true + } else { + return false + } + } + + if didCreateIdentity { + self.readWriteLock.read { MixpanelPersistence.saveIdentity(MixpanelIdentity.init( distinctID: distinctId, peopleDistinctID: people.distinctId, diff --git a/Sources/ReadWriteLock.swift b/Sources/ReadWriteLock.swift index f910ebbf..95f65b3c 100644 --- a/Sources/ReadWriteLock.swift +++ b/Sources/ReadWriteLock.swift @@ -19,7 +19,7 @@ class ReadWriteLock { closure() } } - func write(closure: () -> Void) { + func write(closure: () -> T) -> T { concurrentQueue.sync(flags: .barrier, execute: { closure() })