Skip to content

Commit a84a9cf

Browse files
fix: add frameQueue when adding frame to process
1 parent 115d911 commit a84a9cf

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

Agent/SessionReplay/NRMASessionReplay.swift

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class NRMASessionReplay: NSObject {
5252
/// Tracks which frame counter values contain full snapshots
5353
private var fullSnapshotFrameIndices: Set<Int> = []
5454

55+
private let frameQueue = DispatchQueue(label: "com.newrelic.sessionreplay.frames")
5556

5657
public var isFirstChunk = true
5758
var uncompressedDataSize: Int = 0
@@ -199,20 +200,24 @@ public class NRMASessionReplay: NSObject {
199200

200201
func addFrame(_ frame: SessionReplayFrame) {
201202

202-
rawFrames.append(frame)
203-
204-
// BEGIN PROCESSING FRAME TO FILE
205-
// Process frame to file
206-
DispatchQueue.global(qos: .background).async { [weak self] in
203+
frameQueue.async { [weak self] in
207204
guard let self = self else { return }
205+
self.rawFrames.append(frame)
208206

209-
self.processFrameToFile(frame)
207+
// BEGIN PROCESSING FRAME TO FILE
208+
// Process frame to file
209+
DispatchQueue.global(qos: .background).async { [weak self] in
210+
guard let self = self else { return }
211+
212+
self.processFrameToFile(frame)
213+
214+
// END PROCESSING FRAME TO FILE
215+
}
216+
217+
if self.recordingMode == .error {
218+
self.pruneRawFrames()
219+
}
210220

211-
// END PROCESSING FRAME TO FILE
212-
}
213-
214-
if recordingMode == .error {
215-
pruneRawFrames()
216221
}
217222
}
218223

@@ -357,7 +362,6 @@ public class NRMASessionReplay: NSObject {
357362

358363
/// REPLAY PERSISTENCE
359364

360-
361365
func processFrameToFile(_ frame: SessionReplayFrame) {
362366

363367

0 commit comments

Comments
 (0)