Skip to content

Commit

Permalink
Use serial queue
Browse files Browse the repository at this point in the history
  • Loading branch information
mscwilson committed Sep 20, 2023
1 parent dcb8023 commit 83272be
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 deletions.
18 changes: 6 additions & 12 deletions Sources/Core/Tracker/Tracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -443,32 +443,26 @@ class Tracker: NSObject {
if !dataCollection {
return nil
}
let eventId = DispatchQueue.global(qos: .default).sync {
let eventId = UUID()
DispatchQueue(label: "snowplow.track").async {
event.beginProcessing(withTracker: self)
let eventId = self.processEvent(event)
// Thread.sleep(forTimeInterval: 10)
// print("❗️ after sleep")
self.processEvent(event, eventId)
event.endProcessing(withTracker: self)
return eventId
}
print("❗️ after queue block")
return eventId
}

// MARK: - Event Decoration

func processEvent(_ event: Event) -> UUID? {
objc_sync_enter(self)
func processEvent(_ event: Event, _ eventId: UUID) {
let stateSnapshot = stateManager.trackerState(forProcessedEvent: event)
objc_sync_exit(self)
let trackerEvent = TrackerEvent(event: event, state: stateSnapshot)
let trackerEvent = TrackerEvent(event: event, eventId: eventId, state: stateSnapshot)
if let payload = self.payload(with: trackerEvent) {
emitter.addPayload(toBuffer: payload)
stateManager.afterTrack(event: trackerEvent)
return trackerEvent.eventId
return
}
logDebug(message: "Event not tracked due to filtering")
return nil
}

func payload(with event: TrackerEvent) -> Payload? {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Core/Tracker/TrackerEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class TrackerEvent : InspectableEvent, StateMachineEvent {

private(set) var isService: Bool

init(event: Event, state: TrackerStateSnapshot? = nil) {
eventId = UUID()
init(event: Event, eventId: UUID, state: TrackerStateSnapshot? = nil) {
self.eventId = eventId
timestamp = Int64(Date().timeIntervalSince1970 * 1000)
trueTimestamp = event.trueTimestamp
entities = event.entities
Expand Down

0 comments on commit 83272be

Please sign in to comment.