batchDigest method

Future<void> batchDigest(
  1. List<AppFitEvent> events
)

Digests the provided events.

This is used to digest the provided events and send it to the AppFit dashboard. Before any event is sent to the AppFit dashboard, it is first added to the cache. If the event is successfully sent to the AppFit dashboard, it is removed from the cache, otherwise it will be retried later.

Implementation

Future<void> batchDigest(List<AppFitEvent> events) async {
  final rawEvents =
      await Future.wait(events.map((e) async => await _createRawEvent(e)));
  final result = await _apiClient.trackAll(rawEvents);

  // If the network requests succeeds, remove the event from the cache
  // otherwise, we want to add it to the cache
  switch (result) {
    case true:
      _cache.clear();
      break;
    case false:
      // For now, we need to do nothing.
      break;
  }
}