Skip to content

Commit 99a3bf1

Browse files
authored
addopt strict concurrency (#50)
* remove support for versions of Swift <= 5.6 * Simplify the Package.swift for older Swift versions * bump swift version on example project * add StrictConcurrency to prepare for Swift 6with StrictConcurrency=complete syntax * use a computed property for dateformatter * refine CloudwatchDetail for Sendable conformance
1 parent 5de630d commit 99a3bf1

File tree

4 files changed

+15
-23
lines changed

4 files changed

+15
-23
lines changed

Package.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ let package = Package(
1313
],
1414
targets: [
1515
.target(name: "AWSLambdaEvents",
16-
dependencies: [.product(name: "HTTPTypes", package: "swift-http-types")]),
16+
dependencies: [.product(name: "HTTPTypes", package: "swift-http-types")],
17+
swiftSettings: [.enableExperimentalFeature("StrictConcurrency=complete")]),
1718
.testTarget(name: "AWSLambdaEventsTests",
18-
dependencies: ["AWSLambdaEvents"]),
19+
dependencies: ["AWSLambdaEvents"],
20+
swiftSettings: [.enableExperimentalFeature("StrictConcurrency=complete")]),
1921
]
2022
)

Sources/AWSLambdaEvents/AWSRegion.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public struct AWSRegion: RawRepresentable, Equatable {
2525
self.rawValue = rawValue
2626
}
2727

28-
static var all: [AWSRegion] = [
28+
static let all: [AWSRegion] = [
2929
Self.af_south_1,
3030
Self.ap_northeast_1,
3131
Self.ap_northeast_2,

Sources/AWSLambdaEvents/Cloudwatch.swift

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import struct Foundation.Date
2121
/// EventBridge has the same events/notification types as CloudWatch
2222
public typealias EventBridgeEvent = CloudwatchEvent
2323

24-
public protocol CloudwatchDetail: Decodable {
24+
public protocol CloudwatchDetail: Decodable, Sendable {
2525
static var name: String { get }
2626
}
2727

@@ -37,7 +37,8 @@ extension CloudwatchDetail {
3737
/// https://docs.aws.amazon.com/lambda/latest/dg/services-cloudwatchevents.html
3838
/// https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/EventTypes.html
3939
/// https://docs.aws.amazon.com/eventbridge/latest/userguide/event-types.html
40-
public struct CloudwatchEvent<Detail: CloudwatchDetail>: Decodable {
40+
/// https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-events-structure.html
41+
public struct CloudwatchEvent<Detail: CloudwatchDetail>: Decodable, Sendable {
4142
public let id: String
4243
public let source: String
4344
public let accountId: String
@@ -89,11 +90,11 @@ public enum CloudwatchDetails {
8990
public static let name = "Scheduled Event"
9091
}
9192

92-
public enum EC2 {
93+
public enum EC2: Sendable {
9394
public struct InstanceStateChangeNotification: CloudwatchDetail {
9495
public static let name = "EC2 Instance State-change Notification"
9596

96-
public enum State: String, Codable {
97+
public enum State: String, Codable, Sendable {
9798
case running
9899
case shuttingDown = "shutting-down"
99100
case stopped
@@ -113,7 +114,7 @@ public enum CloudwatchDetails {
113114
public struct SpotInstanceInterruptionNotice: CloudwatchDetail {
114115
public static let name = "EC2 Spot Instance Interruption Warning"
115116

116-
public enum Action: String, Codable {
117+
public enum Action: String, Codable, Sendable {
117118
case hibernate
118119
case stop
119120
case terminate
@@ -131,12 +132,6 @@ public enum CloudwatchDetails {
131132

132133
struct TypeMismatch: Error {
133134
let name: String
134-
let type: Any
135+
let type: any CloudwatchDetail.Type
135136
}
136137
}
137-
138-
#if swift(>=5.6)
139-
extension CloudwatchEvent: Sendable where Detail: Sendable {}
140-
extension CloudwatchDetails.EC2: Sendable {}
141-
extension CloudwatchDetails.Scheduled: Sendable {}
142-
#endif

Sources/AWSLambdaEvents/Utils/DateWrappers.swift

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ public struct ISO8601Coding: Decodable {
3939
self.wrappedValue = date
4040
}
4141

42-
private static let dateFormatter: DateFormatter = Self.createDateFormatter()
43-
44-
private static func createDateFormatter() -> DateFormatter {
42+
private static var dateFormatter: DateFormatter {
4543
let formatter = DateFormatter()
4644
formatter.locale = Locale(identifier: "en_US_POSIX")
4745
formatter.timeZone = TimeZone(secondsFromGMT: 0)
@@ -68,9 +66,7 @@ public struct ISO8601WithFractionalSecondsCoding: Decodable {
6866
self.wrappedValue = date
6967
}
7068

71-
private static let dateFormatter: DateFormatter = Self.createDateFormatter()
72-
73-
private static func createDateFormatter() -> DateFormatter {
69+
private static var dateFormatter: DateFormatter {
7470
let formatter = DateFormatter()
7571
formatter.locale = Locale(identifier: "en_US_POSIX")
7672
formatter.timeZone = TimeZone(secondsFromGMT: 0)
@@ -105,8 +101,7 @@ public struct RFC5322DateTimeCoding: Decodable {
105101
"Expected date to be in RFC5322 date-time format, but `\(string)` is not in the correct format")
106102
}
107103

108-
private static let dateFormatters: [DateFormatter] = Self.createDateFormatters()
109-
private static func createDateFormatters() -> [DateFormatter] {
104+
private static var dateFormatters: [DateFormatter] {
110105
// rfc5322 dates received in SES mails sometimes do not include the day, so need two dateformatters
111106
// one with a day and one without
112107
let formatterWithDay = DateFormatter()

0 commit comments

Comments
 (0)