From b1470880b61032997251493771e70eb6c87e1a43 Mon Sep 17 00:00:00 2001 From: Kha Truong <64438356+khatruong2009@users.noreply.github.com> Date: Fri, 8 Sep 2023 09:29:39 -0700 Subject: [PATCH] chore: moved constructor initializers into a separate init function so that I can use async await --- .../lib/src/remote_constraint_provider.dart | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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()); }