checkExpiredFutures method

void checkExpiredFutures()

Implementation

void checkExpiredFutures() {
  var exception = Exception('Timeout (504)');
  var expires = DateTime.now().subtract(Duration(
      milliseconds: _configService.appSettings.expireFuturesTimeout));

  var markForRemoval = <String>[];
  _pendingFutures.forEach((String key, FutureCallback featureCB) {
    if (featureCB.ts!.isBefore(expires)) {
      _loggerService.error('Promise expired ' + key.toString());
      featureCB.completer?.completeError(exception);
      markForRemoval.add(key);
    }
  });

  _pendingFutures.removeWhere((key, value) => markForRemoval.contains(key));
}