private setUpInternalQueueSubscriber()

in src/shippers/elastic_v3/browser/src/browser_shipper.ts [117:132]


  private setUpInternalQueueSubscriber() {
    this.internalQueue$
      .pipe(
        // Buffer events for 1 second or until we have an optIn value
        bufferWhen(() => merge(this.flush$, interval(1000).pipe(skipWhile(() => this.isOptedIn$.value === undefined)))),
        // Send events (one batch at a time)
        concatMap(async (events) => {
          // Only send if opted-in and there's anything to send
          if (this.isOptedIn$.value === true && events.length > 0) {
            await this.sendEvents(events);
          }
        }),
        map(() => this.queueFlushed$.next())
      )
      .subscribe();
  }