Skip to content

Commit 83e7697

Browse files
committed
Swift 6 support
1 parent fcef65f commit 83e7697

File tree

6 files changed

+206
-30
lines changed

6 files changed

+206
-30
lines changed

.github/workflows/swift-package.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ on: [push]
44

55
jobs:
66
build:
7-
8-
runs-on: macos-13
7+
runs-on: macos-latest
98

109
steps:
1110
- uses: actions/checkout@v2
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "2620"
4+
version = "1.7">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES"
8+
buildArchitectures = "Automatic">
9+
<BuildActionEntries>
10+
<BuildActionEntry
11+
buildForTesting = "YES"
12+
buildForRunning = "YES"
13+
buildForProfiling = "YES"
14+
buildForArchiving = "YES"
15+
buildForAnalyzing = "YES">
16+
<BuildableReference
17+
BuildableIdentifier = "primary"
18+
BlueprintIdentifier = "AsyncReactor"
19+
BuildableName = "AsyncReactor"
20+
BlueprintName = "AsyncReactor"
21+
ReferencedContainer = "container:">
22+
</BuildableReference>
23+
</BuildActionEntry>
24+
</BuildActionEntries>
25+
</BuildAction>
26+
<TestAction
27+
buildConfiguration = "Debug"
28+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
29+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
30+
shouldUseLaunchSchemeArgsEnv = "YES"
31+
shouldAutocreateTestPlan = "YES">
32+
</TestAction>
33+
<LaunchAction
34+
buildConfiguration = "Debug"
35+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
36+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
37+
launchStyle = "0"
38+
useCustomWorkingDirectory = "NO"
39+
ignoresPersistentStateOnLaunch = "NO"
40+
debugDocumentVersioning = "YES"
41+
debugServiceExtension = "internal"
42+
allowLocationSimulation = "YES">
43+
</LaunchAction>
44+
<ProfileAction
45+
buildConfiguration = "Release"
46+
shouldUseLaunchSchemeArgsEnv = "YES"
47+
savedToolIdentifier = ""
48+
useCustomWorkingDirectory = "NO"
49+
debugDocumentVersioning = "YES">
50+
<MacroExpansion>
51+
<BuildableReference
52+
BuildableIdentifier = "primary"
53+
BlueprintIdentifier = "AsyncReactor"
54+
BuildableName = "AsyncReactor"
55+
BlueprintName = "AsyncReactor"
56+
ReferencedContainer = "container:">
57+
</BuildableReference>
58+
</MacroExpansion>
59+
</ProfileAction>
60+
<AnalyzeAction
61+
buildConfiguration = "Debug">
62+
</AnalyzeAction>
63+
<ArchiveAction
64+
buildConfiguration = "Release"
65+
revealArchiveInOrganizer = "YES">
66+
</ArchiveAction>
67+
</Scheme>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "2620"
4+
version = "1.7">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES"
8+
buildArchitectures = "Automatic">
9+
<BuildActionEntries>
10+
<BuildActionEntry
11+
buildForTesting = "YES"
12+
buildForRunning = "YES"
13+
buildForProfiling = "YES"
14+
buildForArchiving = "YES"
15+
buildForAnalyzing = "YES">
16+
<BuildableReference
17+
BuildableIdentifier = "primary"
18+
BlueprintIdentifier = "Reactor"
19+
BuildableName = "Reactor"
20+
BlueprintName = "Reactor"
21+
ReferencedContainer = "container:">
22+
</BuildableReference>
23+
</BuildActionEntry>
24+
</BuildActionEntries>
25+
</BuildAction>
26+
<TestAction
27+
buildConfiguration = "Debug"
28+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
29+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
30+
shouldUseLaunchSchemeArgsEnv = "YES"
31+
shouldAutocreateTestPlan = "YES">
32+
</TestAction>
33+
<LaunchAction
34+
buildConfiguration = "Debug"
35+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
36+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
37+
launchStyle = "0"
38+
useCustomWorkingDirectory = "NO"
39+
ignoresPersistentStateOnLaunch = "NO"
40+
debugDocumentVersioning = "YES"
41+
debugServiceExtension = "internal"
42+
allowLocationSimulation = "YES">
43+
</LaunchAction>
44+
<ProfileAction
45+
buildConfiguration = "Release"
46+
shouldUseLaunchSchemeArgsEnv = "YES"
47+
savedToolIdentifier = ""
48+
useCustomWorkingDirectory = "NO"
49+
debugDocumentVersioning = "YES">
50+
<MacroExpansion>
51+
<BuildableReference
52+
BuildableIdentifier = "primary"
53+
BlueprintIdentifier = "Reactor"
54+
BuildableName = "Reactor"
55+
BlueprintName = "Reactor"
56+
ReferencedContainer = "container:">
57+
</BuildableReference>
58+
</MacroExpansion>
59+
</ProfileAction>
60+
<AnalyzeAction
61+
buildConfiguration = "Debug">
62+
</AnalyzeAction>
63+
<ArchiveAction
64+
buildConfiguration = "Release"
65+
revealArchiveInOrganizer = "YES">
66+
</ArchiveAction>
67+
</Scheme>

Package.swift

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
// swift-tools-version: 5.7
2-
// The swift-tools-version declares the minimum version of Swift required to build this package.
1+
// swift-tools-version: 6.2
32

43
import PackageDescription
54

@@ -12,7 +11,6 @@ let package = Package(
1211
.macOS(.v12)
1312
],
1413
products: [
15-
// Products define the executables and libraries a package produces, and make them visible to other packages.
1614
.library(
1715
name: "AsyncReactor",
1816
targets: ["AsyncReactor"]
@@ -22,13 +20,8 @@ let package = Package(
2220
targets: ["Reactor"]
2321
)
2422
],
25-
dependencies: [
26-
// Dependencies declare other packages that this package depends on.
27-
// .package(url: /* package url */, from: "1.0.0"),
28-
],
23+
dependencies: [],
2924
targets: [
30-
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
31-
// Targets can depend on other targets in this package, and on products in packages this package depends on.
3225
.target(
3326
name: "ReactorBase",
3427
dependencies: []

Package@swift-5.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// swift-tools-version: 5.9
2+
3+
import PackageDescription
4+
5+
let package = Package(
6+
name: "AsyncReactor",
7+
platforms: [
8+
.iOS(.v15),
9+
.tvOS(.v15),
10+
.watchOS(.v8),
11+
.macOS(.v12)
12+
],
13+
products: [
14+
.library(
15+
name: "AsyncReactor",
16+
targets: ["AsyncReactor"]
17+
),
18+
.library(
19+
name: "Reactor",
20+
targets: ["Reactor"]
21+
)
22+
],
23+
dependencies: [],
24+
targets: [
25+
.target(
26+
name: "ReactorBase",
27+
dependencies: []
28+
),
29+
.target(
30+
name: "Reactor",
31+
dependencies: ["ReactorBase"]
32+
),
33+
.target(
34+
name: "AsyncReactor",
35+
dependencies: ["ReactorBase"]
36+
),
37+
.testTarget(
38+
name: "AsyncReactorTests",
39+
dependencies: ["AsyncReactor"],
40+
path: "Tests"
41+
),
42+
]
43+
)

Sources/ReactorBase/ReactorBase.swift

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,33 +53,40 @@ extension ReactorBase {
5353

5454
// MARK: - Cancellation Support
5555

56-
public struct CancelId: Hashable {
57-
let id: AnyHashable
56+
public struct CancelId: Hashable, Sendable {
57+
let id: UUID
5858
let mode: Mode
5959

60-
public init(id: AnyHashable, mode: Mode) {
60+
public init(id: UUID, mode: Mode) {
6161
self.id = id
6262
self.mode = mode
6363
}
6464

65-
public struct Mode: OptionSet, Hashable {
65+
public struct Mode: OptionSet, Hashable, Sendable {
6666
public let rawValue: Int
6767

6868
public init(rawValue: Int) {
6969
self.rawValue = rawValue
7070
}
7171

72-
public static let lifecycle = Mode(rawValue: 1 << 0)
73-
public static let inFlight = Mode(rawValue: 1 << 1)
72+
public static var lifecycle: Mode {
73+
Mode(rawValue: 1 << 0)
74+
}
75+
76+
public static var inFlight: Mode {
77+
Mode(rawValue: 1 << 1)
78+
}
7479
}
7580
}
7681

77-
struct TasksHolder {
78-
@MainActor
79-
static var tasks = [TaskKey: Task<Void, Never>]()
82+
@MainActor
83+
class TasksHolder {
84+
var tasks = [TaskKey: Task<Void, Never>]()
85+
86+
static var shared: TasksHolder = TasksHolder()
8087
}
8188

82-
struct TaskKey: Hashable {
89+
struct TaskKey: Hashable, Sendable {
8390
let reactorId: ObjectIdentifier
8491
let id: CancelId
8592

@@ -95,46 +102,46 @@ extension ReactorBase {
95102
let key = TaskKey(reactor: self, id: id)
96103

97104
if id.mode.contains(.inFlight) {
98-
TasksHolder.tasks[key]?.cancel()
105+
TasksHolder.shared.tasks[key]?.cancel()
99106
}
100107

101108
let task = Task {
102109
await self.action(action)
103110
}
104111

105-
TasksHolder.tasks[key] = task
112+
TasksHolder.shared.tasks[key] = task
106113

107114
await task.value
108115

109116
if !task.isCancelled {
110-
TasksHolder.tasks.removeValue(forKey: key)
117+
TasksHolder.shared.tasks.removeValue(forKey: key)
111118
}
112119
}
113120

114121
public func send(_ action: Action, id: CancelId) {
115122
Task { await self.action(action, id: id) }
116123
}
117124

118-
public func lifecycleTask(_ action: @escaping @Sendable () async -> Void) {
125+
public func lifecycleTask(_ action: @escaping @Sendable () async -> ()) {
119126
Task { @MainActor in
120127
let key = TaskKey(reactor: self, id: .init(id: UUID(), mode: .lifecycle))
121128

122129
let task = Task.detached {
123130
await action()
124-
await MainActor.run { _ = TasksHolder.tasks.removeValue(forKey: key) }
131+
await MainActor.run { _ = TasksHolder.shared.tasks.removeValue(forKey: key) }
125132
}
126133

127-
TasksHolder.tasks[key] = task
134+
TasksHolder.shared.tasks[key] = task
128135
}
129136
}
130137

131138
public func cancelLifecycleTasks() {
132139
Task { @MainActor in
133-
let keys = TasksHolder.tasks.keys.filter { $0.id.mode.contains(.lifecycle) && $0.reactorId == ObjectIdentifier(self) }
140+
let keys = TasksHolder.shared.tasks.keys.filter { $0.id.mode.contains(.lifecycle) && $0.reactorId == ObjectIdentifier(self) }
134141

135142
for key in keys {
136-
TasksHolder.tasks[key]?.cancel()
137-
TasksHolder.tasks.removeValue(forKey: key)
143+
TasksHolder.shared.tasks[key]?.cancel()
144+
TasksHolder.shared.tasks.removeValue(forKey: key)
138145
}
139146
}
140147
}

0 commit comments

Comments
 (0)