Skip to content

Commit ea842e8

Browse files
authored
feat: Make models Sendable (#829)
1 parent a001f88 commit ea842e8

File tree

28 files changed

+347
-343
lines changed

28 files changed

+347
-343
lines changed

Sources/ClientRuntime/Networking/CRTError+Error.swift

Lines changed: 0 additions & 15 deletions
This file was deleted.

Sources/ClientRuntime/PrimitiveTypeExtensions/Indirect.swift

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,28 @@
55
// SPDX-License-Identifier: Apache-2.0
66
//
77

8+
import class Foundation.NSRecursiveLock
9+
810
@propertyWrapper
9-
public class Indirect<T> {
10-
public var wrappedValue: Optional<T>
11+
public final class Indirect<T: Sendable>: @unchecked Sendable {
12+
private let lock = NSRecursiveLock()
13+
private var _wrappedValue: Optional<T>
14+
15+
public var wrappedValue: Optional<T> {
16+
get {
17+
lock.lock()
18+
defer { lock.unlock() }
19+
return _wrappedValue
20+
}
21+
set {
22+
lock.lock()
23+
defer { lock.unlock() }
24+
_wrappedValue = newValue
25+
}
26+
}
1127

1228
public init(wrappedValue: Optional<T>) {
13-
self.wrappedValue = wrappedValue
29+
self._wrappedValue = wrappedValue
1430
}
1531
}
1632

Sources/Smithy/ByteStream.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import class Foundation.FileHandle
99
import struct Foundation.Data
1010

11-
public enum ByteStream {
11+
public enum ByteStream: Sendable {
1212
case data(Data?)
1313
case stream(Stream)
1414
case noStream

Sources/Smithy/Document/SmithyDocument.swift

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
import struct Foundation.Data
99
import struct Foundation.Date
1010

11-
public protocol SmithyDocument {
11+
public protocol SmithyDocument: Sendable {
1212

13+
/// The Smithy type corresponding to the data stored in this document.
1314
var type: ShapeType { get }
1415

1516
// "as" methods throw if the document doesn't match the requested type.
@@ -116,6 +117,20 @@ public extension SmithyDocument {
116117

117118
extension SmithyDocument {
118119

120+
/// Compares two `SmithyDocument`-conforming values, checking for equality.
121+
///
122+
/// Two `SmithyDocument`s are equal if they have the same type and equal values.
123+
///
124+
/// Two Smithy `list` documents are equal if they have equal documents at every index.
125+
///
126+
/// Two Smithy `map` documents are equal if they have the same set of keys, and equal values for every key.
127+
///
128+
/// - note: Because `SmithyDocument` is a protocol, it cannot conform to `Equatable`; the type-erased
129+
/// container type ``Document`` is used to provide Smithy documents with equatability.
130+
/// - Parameters:
131+
/// - lhs: The first `SmithyDocument` to compare.
132+
/// - rhs: The second `SmithyDocument` to compare.
133+
/// - Returns: `true` if the two `SmithyDocument`s are equal, `false` otherwise.
119134
public static func isEqual(_ lhs: SmithyDocument, _ rhs: SmithyDocument) -> Bool {
120135
switch (lhs.type, rhs.type) {
121136
case (.blob, .blob):

Sources/Smithy/Stream.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import struct Foundation.Data
99

1010
/// Protocol that provides reading data from a stream
11-
public protocol ReadableStream: AnyObject {
11+
public protocol ReadableStream: AnyObject, Sendable {
1212
/// Returns the current position in the stream
1313
var position: Data.Index { get }
1414

@@ -45,7 +45,7 @@ public protocol ReadableStream: AnyObject {
4545
}
4646

4747
/// Protocol that provides writing data to a stream
48-
public protocol WriteableStream: AnyObject {
48+
public protocol WriteableStream: AnyObject, Sendable {
4949
/// Writes the contents of `data` to the stream
5050
/// - Parameter data: data to write
5151
func write(contentsOf data: Data) throws

Sources/SmithyChecksums/ChunkedStream.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import class SmithyStreams.BufferedStream
1616
/// URLSessionHTTPClient streams chunked payloads using this stream type.
1717
/// CRTClientEngine uses only the reader provided by this type to create chunks, then it
1818
/// streams them itself.
19-
public class ChunkedStream {
20-
private var inputStream: Stream
19+
public class ChunkedStream: @unchecked Sendable {
20+
private let inputStream: Stream
2121
private var signingConfig: SigningConfig
2222
private var previousSignature: String
2323
private var trailingHeaders: Headers

Sources/SmithyChecksums/ValidatingBufferedStream.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import struct Foundation.Data
1212
import AwsCommonRuntimeKit
1313
import class SmithyStreams.BufferedStream
1414

15-
public class ValidatingBufferedStream {
15+
public class ValidatingBufferedStream: @unchecked Sendable {
1616
private var stream: BufferedStream
1717
private var checksumAlgorithm: ChecksumAlgorithm
1818
private var checksum: (any Checksum)

Sources/SmithyEventStreams/DefaultMessageEncoderStream.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import SmithyEventStreamsAuthAPI
1111
import struct Foundation.Data
1212

1313
/// Stream adapter that encodes input into `Data` objects.
14-
public class DefaultMessageEncoderStream<Event>: MessageEncoderStream, Stream {
14+
public class DefaultMessageEncoderStream<Event>: MessageEncoderStream, Stream, @unchecked Sendable {
1515

1616
let stream: AsyncThrowingStream<Event, Error>
1717
let messageEncoder: MessageEncoder

Sources/SmithyEventStreamsAPI/EventStreamError.swift

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,3 @@ public enum EventStreamError: Error {
1515
/// This may be due to missing required headers
1616
case invalidMessage(String)
1717
}
18-
19-
extension AsyncThrowingStream: Equatable where Element: Equatable {
20-
21-
public static func == (lhs: AsyncThrowingStream, rhs: AsyncThrowingStream) -> Bool {
22-
// TODO: Remove as part of https://github.com/awslabs/aws-sdk-swift/issues/898
23-
return false
24-
}
25-
}

Sources/SmithyHTTPAPI/Headers.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// SPDX-License-Identifier: Apache-2.0
66
//
77

8-
public struct Headers {
8+
public struct Headers: Sendable {
99
public var headers: [Header] = []
1010

1111
/// Creates an empty instance.
@@ -197,7 +197,7 @@ extension Array where Element == Header {
197197
}
198198
}
199199

200-
public struct Header {
200+
public struct Header: Sendable {
201201
public var name: String
202202
public var value: [String]
203203

0 commit comments

Comments
 (0)