diff --git a/packages/logging_cloudwatch/aws_logging_cloudwatch/lib/src/remote_constraint_provider.dart b/packages/logging_cloudwatch/aws_logging_cloudwatch/lib/src/remote_constraint_provider.dart index 57a73a3086..799ae159ff 100644 --- a/packages/logging_cloudwatch/aws_logging_cloudwatch/lib/src/remote_constraint_provider.dart +++ b/packages/logging_cloudwatch/aws_logging_cloudwatch/lib/src/remote_constraint_provider.dart @@ -38,8 +38,7 @@ class DefaultRemoteLoggingConstraintProvider required AWSCredentialsProvider credentialsProvider, }) : _config = config, _credentialsProvider = credentialsProvider { - _fetchAndCacheConstraintFromEndpoint(); // Fetch once immediately on initialize - _refreshConstraintPeriodically(); + init(); } final DefaultRemoteConfiguration _config; @@ -61,6 +60,15 @@ class DefaultRemoteLoggingConstraintProvider @override String get runtimeTypeName => 'DefaultRemoteLoggingConstraintProvider'; + /// Initializes the [DefaultRemoteLoggingConstraintProvider] by fetching + /// the constraint from the endpoint initially and then + /// starting the refresh timer afterwards. + Future init() async { + await _fetchAndCacheConstraintFromEndpoint(); + await _refreshConstraintPeriodically(); + return null; + } + Future _saveConstraintLocally(LoggingConstraint constraint) async { await storage.saveConstraintLocally(constraint.toJson()); }