Skip to content
Closed
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
31 changes: 25 additions & 6 deletions packages/replay/src/eventBuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ export class EventBufferProxy implements EventBuffer {
return this._used.finish();
}

/** @inheritDoc */
public finishImmediate(): ReplayRecordingData {
return this._used.finishImmediate();
}

/** Ensure the worker has loaded. */
private async _ensureWorkerIsLoaded(): Promise<void> {
try {
Expand Down Expand Up @@ -139,14 +144,18 @@ class EventBufferArray implements EventBuffer {

public finish(): Promise<string> {
return new Promise<string>(resolve => {
// Make a copy of the events array reference and immediately clear the
// events member so that we do not lose new events while uploading
// attachment.
const eventsRet = this._events;
this._events = [];
resolve(JSON.stringify(eventsRet));
resolve(this.finishImmediate());
});
}

public finishImmediate(): string {
// Make a copy of the events array reference and immediately clear the
// events member so that we do not lose new events while uploading
// attachment.
const eventsRet = this._events;
this._events = [];
return JSON.stringify(eventsRet);
}
}

/**
Expand Down Expand Up @@ -252,6 +261,16 @@ export class EventBufferCompressionWorker implements EventBuffer {
return this._finishRequest(this._getAndIncrementId());
}

/** @inheritdoc */
public finishImmediate(): string {
const events = this._pendingEvents;

// We want to finish this, but just ignore the result
void this._finishRequest(this._getAndIncrementId());

return JSON.stringify(events);
}

/**
* Post message to worker and wait for response before resolving promise.
*/
Expand Down
5 changes: 5 additions & 0 deletions packages/replay/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ export interface EventBuffer {
* Clears and returns the contents of the buffer.
*/
finish(): Promise<ReplayRecordingData>;

/**
* Clear & immediately return the contents of the buffer in a sync way.
*/
finishImmediate(): ReplayRecordingData;
}

export type AddUpdateCallback = () => boolean | void;
Expand Down