Skip to content

Commit 2ffebfc

Browse files
Merge pull request #13 from NeedleInAJayStack/feat/swift-6-concurrency
Swift 6 concurrency
2 parents b33d0ea + 9861953 commit 2ffebfc

File tree

15 files changed

+87
-62
lines changed

15 files changed

+87
-62
lines changed

Sources/Haystack/API/HisItem.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/// A timestamp/value pair.
2-
public struct HisItem {
2+
public struct HisItem: Sendable {
33
public let ts: DateTime
44
public let val: any Val
55

Sources/Haystack/API/HisReadRange.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Foundation
22

33
/// Query-able DateTime ranges, which support relative and absolute values.
4-
public enum HisReadRange {
4+
public enum HisReadRange: Sendable {
55
case today
66
case yesterday
77
case date(Haystack.Date)

Sources/Haystack/DateTime.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public struct DateTime: Val {
191191
}
192192
}
193193

194-
var calendar = Calendar(identifier: .gregorian)
194+
let calendar = Calendar(identifier: .gregorian)
195195

196196
// DateTime + Codable
197197
extension DateTime {

Sources/Haystack/IO/ZincTokenizer.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ZincTokenizer {
1818
try consume()
1919
}
2020

21-
public convenience init(_ string: String) throws {
21+
convenience init(_ string: String) throws {
2222
guard let data = string.data(using: .utf8) else {
2323
throw ZincTokenizerError.inputIsNotUtf8
2424
}

Sources/Haystack/Val.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ extension Val {
2424
}
2525
}
2626

27-
public enum ValType: String, CaseIterable {
27+
public enum ValType: String, CaseIterable, Sendable {
2828
case Bool
2929
case Coord
3030
case Date

Sources/HaystackClient/Client.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class Client: API {
2222
let fetcher: Fetcher
2323

2424
/// Set when `open` is called.
25-
private var authToken: String? = nil
25+
private var authToken: String?
2626

2727
private let jsonEncoder = JSONEncoder()
2828
private let jsonDecoder = JSONDecoder()

Sources/HaystackServer/HaystackServer.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ import Haystack
33

44
/// A HaystackServer is a server that implements the Haystack API.
55
/// It translates API calls into operations on the underlying data stores.
6-
public class HaystackServer: API {
6+
public final class HaystackServer: API, Sendable {
77
let recordStore: RecordStore
88
let historyStore: HistoryStore
99
let watchStore: WatchStore
1010

11-
let onInvokeAction: (Haystack.Ref, String, [String: any Haystack.Val]) async throws -> Haystack.Grid
12-
let onEval: (String) async throws -> Haystack.Grid
11+
let onInvokeAction: @Sendable (Haystack.Ref, String, [String: any Haystack.Val]) async throws -> Haystack.Grid
12+
let onEval: @Sendable (String) async throws -> Haystack.Grid
1313

1414
public init(
1515
recordStore: RecordStore,
1616
historyStore: HistoryStore,
1717
watchStore: WatchStore,
18-
onInvokeAction: @escaping (Haystack.Ref, String, [String: any Haystack.Val]) async throws -> Haystack.Grid = { _, _, _ in
18+
onInvokeAction: @escaping @Sendable (Haystack.Ref, String, [String: any Haystack.Val]) async throws -> Haystack.Grid = { _, _, _ in
1919
GridBuilder().toGrid()
2020
},
21-
onEval: @escaping (String) async throws -> Haystack.Grid = { _ in
21+
onEval: @escaping @Sendable (String) async throws -> Haystack.Grid = { _ in
2222
GridBuilder().toGrid()
2323
}
2424
) {

Sources/HaystackServer/Stores/HistoryStore.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Haystack
22

33
/// Defines a storage system that allows reading and writing of Haystack history data.
4-
public protocol HistoryStore {
4+
public protocol HistoryStore: Sendable {
55
/// Reads history data for a given ID and time range.
66
func hisRead(id: Haystack.Ref, range: Haystack.HisReadRange) async throws -> [Haystack.Dict]
77

Sources/HaystackServer/Stores/RecordStore.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Haystack
22

33
/// Defines a storage system that allows reading and writing of Haystack records.
4-
public protocol RecordStore {
4+
public protocol RecordStore: Sendable {
55
/// Reads records from the store based on a list of IDs.
66
func read(ids: [Haystack.Ref]) async throws -> [Haystack.Dict]
77

@@ -12,7 +12,7 @@ public protocol RecordStore {
1212
func commitAll(diffs: [RecordDiff]) async throws -> [RecordDiff]
1313
}
1414

15-
public struct RecordDiff {
15+
public struct RecordDiff: Sendable {
1616
public init(
1717
id: Haystack.Ref,
1818
old: Haystack.Dict?,

Sources/HaystackServer/Stores/WatchStore.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22
import Haystack
33

44
/// Defines a storage system that allows stateful storage of system watches.
5-
public protocol WatchStore {
5+
public protocol WatchStore: Sendable {
66
func read(watchId: String) async throws -> WatchResponse
77
func create(ids: [Haystack.Ref], lease: Haystack.Number?) async throws -> String
88
func addIds(watchId: String, ids: [Haystack.Ref]) async throws
@@ -11,7 +11,7 @@ public protocol WatchStore {
1111
func delete(watchId: String) async throws
1212
}
1313

14-
public struct WatchResponse {
14+
public struct WatchResponse: Sendable {
1515
public let ids: [Haystack.Ref]
1616
public let lease: Haystack.Number
1717
public let lastReported: Foundation.Date?

0 commit comments

Comments
 (0)