You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sources/BreezeDynamoDBService/BreezeDynamoDBService.swift
+23-3Lines changed: 23 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -33,7 +33,25 @@ public struct BreezeDynamoDBService: BreezeDynamoDBServing {
33
33
privateletlogger:Logger
34
34
privateletawsClient:AWSClient
35
35
privatelethttpClient:HTTPClient
36
-
36
+
privateletshutdownState:ShutdownState
37
+
38
+
/// Error types for BreezeDynamoDBService
39
+
enumBreezeDynamoDBServiceError:Error{
40
+
case alreadyShutdown
41
+
}
42
+
43
+
/// Actor to manage shutdown state safely
44
+
privateactorShutdownState{
45
+
privatevarisShutdown=false
46
+
47
+
func markShutdown()throws{
48
+
guard !isShutdown else{
49
+
throwBreezeDynamoDBServiceError.alreadyShutdown
50
+
}
51
+
isShutdown =true
52
+
}
53
+
}
54
+
37
55
/// Initializes the BreezeDynamoDBService with the provided configuration.
38
56
/// - Parameters:
39
57
/// - config: The configuration for the DynamoDB service.
@@ -76,6 +94,7 @@ public struct BreezeDynamoDBService: BreezeDynamoDBServing {
76
94
tableName: config.tableName,
77
95
keyName: config.keyName
78
96
)
97
+
self.shutdownState =ShutdownState()
79
98
logger.info("DBManager is ready.")
80
99
}
81
100
@@ -89,9 +108,10 @@ public struct BreezeDynamoDBService: BreezeDynamoDBServing {
89
108
/// - Throws: An error if the shutdown process fails.
90
109
/// This method ensures that the AWS client and HTTP client are properly shutdown before marking the service as shutdown.
91
110
/// It also logs the shutdown process.
92
-
/// This method is idempotent;
93
-
/// - Important: This method must be called at leat once to ensure that resources are released properly. If the method is not called, it will lead to a crash.
111
+
/// This method is idempotent and will throw if called multiple times to prevent double shutdown.
112
+
/// - Important: This method must be called at least once to ensure that resources are released properly. If the method is not called, it will lead to a crash.
0 commit comments