TrueTimeEngine constructor

TrueTimeEngine({
  1. required List<TimeSource> sources,
  2. MonotonicClock? clock,
  3. TrueTimeConfig config = const TrueTimeConfig(),
  4. AnchorStore? store,
  5. BootEpochProvider epochProvider = const UnknownBootEpochProvider(),
  6. TimeScheduler? scheduler,
  7. Random? random,
  8. bool autoRefresh = true,
  9. WallClockReader? wallClock,
  10. Duration diagnosticInterval = const Duration(seconds: 30),
  11. Duration wallClockJumpThreshold = const Duration(seconds: 2),
  12. bool foreground = true,
})

Implementation

TrueTimeEngine({
  required List<TimeSource> sources,
  MonotonicClock? clock,
  this.config = const TrueTimeConfig(),
  AnchorStore? store,
  this.epochProvider = const UnknownBootEpochProvider(),
  TimeScheduler? scheduler,
  Random? random,
  this.autoRefresh = true,
  this.wallClock,
  this.diagnosticInterval = const Duration(seconds: 30),
  this.wallClockJumpThreshold = const Duration(seconds: 2),
  bool foreground = true,
}) : sources = List.unmodifiable(sources),
     clock = clock ?? createPlatformClock(),
     store = store == null ? null : SerializingAnchorStore.wrap(store),
     _scheduler = scheduler ?? TimerScheduler(),
     _random = random ?? Random(),
     _foreground = foreground,
     _pool = _QueryPool(config.maxConcurrentSources) {
  config.validate();
  if (sources.length > maximumSources) {
    throw ArgumentError.value(
      sources.length,
      'sources',
      'At most $maximumSources sources are supported',
    );
  }
  if (diagnosticInterval <= Duration.zero ||
      wallClockJumpThreshold <= Duration.zero) {
    throw ArgumentError('Diagnostic durations must be positive');
  }
  final ids = <String>{}, endpoints = <String>{};
  for (final source in sources) {
    if (source.id.isEmpty ||
        source.endpoint.isEmpty ||
        source.configurationKey.isEmpty ||
        !ids.add(source.id) ||
        !endpoints.add(source.endpoint.toLowerCase())) {
      throw ArgumentError(
        'Source ids, endpoints, and configuration identities must be valid and unique',
      );
    }
  }
}