Skip to content

Commit

Permalink
chore: moved constructor initializers into a separate init function s…
Browse files Browse the repository at this point in the history
…o that I can use async await
  • Loading branch information
khatruong2009 committed Sep 8, 2023
1 parent 9f98943 commit b147088
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ class DefaultRemoteLoggingConstraintProvider
required AWSCredentialsProvider credentialsProvider,
}) : _config = config,
_credentialsProvider = credentialsProvider {
_fetchAndCacheConstraintFromEndpoint(); // Fetch once immediately on initialize
_refreshConstraintPeriodically();
init();
}

final DefaultRemoteConfiguration _config;
Expand All @@ -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<LoggingConstraint?> init() async {
await _fetchAndCacheConstraintFromEndpoint();
await _refreshConstraintPeriodically();
return null;
}

Future<void> _saveConstraintLocally(LoggingConstraint constraint) async {
await storage.saveConstraintLocally(constraint.toJson());
}
Expand Down

0 comments on commit b147088

Please sign in to comment.