Skip to content

Commit

Permalink
Add Sendable Conformance to Field and Reference Types (#353)
Browse files Browse the repository at this point in the history
* Add Sendable conformance to Field property wrapper

Makes the Field<C> property wrapper Sendable-compliant to better support concurrent operations and Swift's actor isolation system.

* fix: make Field property wrapper conditionally Sendable

- Remove direct Sendable conformance from Field struct
- Add conditional Sendable conformance via extension where C: Sendable

* fix: add Sendable conformance to Reference struct
  • Loading branch information
vamsii777 authored Dec 1, 2024
1 parent 807553c commit 6654e80
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions Sources/Meow/KeyPathModel/KeyPathModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,9 @@ public struct Field<C: Codable>: Codable, _QueryableFieldRepresentable {
}
}

// Add conditional Sendable conformance
extension Field: Sendable where C: Sendable {}

extension Field: Equatable where C: Equatable {
public static func ==(lhs: Self, rhs: Self) -> Bool {
lhs.wrappedValue == rhs.wrappedValue
Expand Down
2 changes: 1 addition & 1 deletion Sources/Meow/Reference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import NIO
/// let post: Post = try await postRef.resolve(in: req.meow)
/// return post
/// }
public struct Reference<M: ReadableModel>: Resolvable, Hashable, PrimitiveEncodable {
public struct Reference<M: ReadableModel>: Resolvable, Hashable, PrimitiveEncodable, Sendable where M.Identifier: Sendable {
/// The referenced id
public let reference: M.Identifier

Expand Down

0 comments on commit 6654e80

Please sign in to comment.