Skip to content
Open
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
2 changes: 2 additions & 0 deletions packages/core/src/__tests__/methods/process.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ describe('process', () => {
jest.spyOn(client.isReady, 'value', 'get').mockReturnValue(true);
// @ts-ignore
await client.onReady();
// @ts-ignore
await client.processPendingEvents();
expectedEvent = {
...expectedEvent,
context: { ...store.context.get() },
Expand Down
18 changes: 10 additions & 8 deletions packages/core/src/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,13 @@ export class SegmentClient {
// check if the app was opened from a deep link
this.trackDeepLinks(),
]);

await this.onReady();
this.isReady.value = true;

// Process all pending events
await this.processPendingEvents();
// Trigger manual flush
this.flushPolicyExecuter.manualFlush();
} catch (error) {
this.reportInternalError(
new SegmentError(
Expand Down Expand Up @@ -561,15 +565,13 @@ export class SegmentClient {
// Start flush policies
// This should be done before any pending events are added to the queue so that any policies that rely on events queued can trigger accordingly
this.setupFlushPolicies();

// Send all events in the queue
}
private async processPendingEvents() {
const pending = await this.store.pendingEvents.get(true);
for (const e of pending) {
await this.startTimelineProcessing(e);
await this.store.pendingEvents.remove(e);
for (const event of pending) {
await this.startTimelineProcessing(event);
await this.store.pendingEvents.remove(event);
}

this.flushPolicyExecuter.manualFlush();
}

async flush(): Promise<void> {
Expand Down
Loading