public flush()

in packages/sdk/src/EventSenderEngine.ts [104:133]


  public flush(): Promise<boolean> {
    this.clearPendingFlush();
    const batchSize = this.writeQueue.length;
    if (batchSize === 0) {
      return Promise.resolve(true);
    }
    return this.upload({
      clientSecret: this.clientSecret,
      sendTime: new Date().toISOString(),
      events: this.writeQueue.splice(0, this.maxBatchSize),
    })
      .then(errors => {
        if (errors.length === 0) {
          this.logger.info?.('Confidence: successfully uploaded %i events', batchSize);
          return true;
        }
        const distinctErrorMessages = Array.from(new Set(errors.map(({ reason, message }) => message || reason)));
        this.logger.warn?.(
          'Confidence: failed to upload %i out of %i event(s) with the following errors: %o',
          errors.length,
          batchSize,
          distinctErrorMessages,
        );
        return false;
      })
      .catch(error => {
        this.logger.error?.('Confidence: failed to upload %i events.', batchSize, error);
        return false;
      });
  }