@@ -20,24 +20,11 @@ import Glibc
20
20
import WinSDK
21
21
#endif
22
22
23
- public struct LocalTestingActorAddress : Hashable , Sendable , Codable {
24
- public let address : String
25
-
26
- public init ( parse address: String ) {
27
- self . address = address
28
- }
29
-
30
- public init ( from decoder: Decoder ) throws {
31
- let container = try decoder. singleValueContainer ( )
32
- self . address = try container. decode ( String . self)
33
- }
34
-
35
- public func encode( to encoder: Encoder ) throws {
36
- var container = encoder. singleValueContainer ( )
37
- try container. encode ( self . address)
38
- }
39
- }
40
-
23
+ /// A `DistributedActorSystem` designed for local only testing.
24
+ ///
25
+ /// It will crash on any attempt of remote communication, but can be useful
26
+ /// for learning about `distributed actor` isolation, as well as early
27
+ /// prototyping stages of development where a real system is not necessary yet.
41
28
@available ( SwiftStdlib 5 . 7 , * )
42
29
public final class LocalTestingDistributedActorSystem : DistributedActorSystem , @unchecked Sendable {
43
30
public typealias ActorID = LocalTestingActorAddress
@@ -86,9 +73,6 @@ public final class LocalTestingDistributedActorSystem: DistributedActorSystem, @
86
73
}
87
74
88
75
public func resignID( _ id: ActorID ) {
89
- guard self . assignedIDsLock. withLock ( { self . assignedIDs. contains ( id) } ) else {
90
- fatalError ( " Attempted to resign unknown id ' \( id) ' " )
91
- }
92
76
self . activeActorsLock. withLock {
93
77
self . activeActors. removeValue ( forKey: id)
94
78
}
@@ -109,7 +93,7 @@ public final class LocalTestingDistributedActorSystem: DistributedActorSystem, @
109
93
Act. ID == ActorID ,
110
94
Err: Error ,
111
95
Res: SerializationRequirement {
112
- fatalError ( " Attempted to make remote call on actor \( actor ) in a local-only actor system " )
96
+ fatalError ( " Attempted to make remote call to \( target ) on actor \( actor ) using a local-only actor system " )
113
97
}
114
98
115
99
public func remoteCallVoid< Act, Err> (
@@ -121,7 +105,7 @@ public final class LocalTestingDistributedActorSystem: DistributedActorSystem, @
121
105
where Act: DistributedActor ,
122
106
Act. ID == ActorID ,
123
107
Err: Error {
124
- fatalError ( " Attempted to make remote call on actor \( actor ) in a local-only actor system " )
108
+ fatalError ( " Attempted to make remote call to \( target ) on actor \( actor ) using a local-only actor system " )
125
109
}
126
110
127
111
private struct ActorIDProvider {
@@ -140,6 +124,26 @@ public final class LocalTestingDistributedActorSystem: DistributedActorSystem, @
140
124
}
141
125
}
142
126
127
+ @available ( SwiftStdlib 5 . 7 , * )
128
+ public struct LocalTestingActorAddress : Hashable , Sendable , Codable {
129
+ public let address : String
130
+
131
+ public init ( parse address: String ) {
132
+ self . address = address
133
+ }
134
+
135
+ public init ( from decoder: Decoder ) throws {
136
+ let container = try decoder. singleValueContainer ( )
137
+ self . address = try container. decode ( String . self)
138
+ }
139
+
140
+ public func encode( to encoder: Encoder ) throws {
141
+ var container = encoder. singleValueContainer ( )
142
+ try container. encode ( self . address)
143
+ }
144
+ }
145
+
146
+ @available ( SwiftStdlib 5 . 7 , * )
143
147
public struct LocalTestingInvocationEncoder : DistributedTargetInvocationEncoder {
144
148
public typealias SerializationRequirement = Codable
145
149
@@ -164,7 +168,8 @@ public struct LocalTestingInvocationEncoder: DistributedTargetInvocationEncoder
164
168
}
165
169
}
166
170
167
- public class LocalTestingInvocationDecoder : DistributedTargetInvocationDecoder {
171
+ @available ( SwiftStdlib 5 . 7 , * )
172
+ public final class LocalTestingInvocationDecoder : DistributedTargetInvocationDecoder {
168
173
public typealias SerializationRequirement = Codable
169
174
170
175
public func decodeGenericSubstitutions( ) throws -> [ Any . Type ] {
@@ -197,6 +202,7 @@ public struct LocalTestingDistributedActorSystemError: DistributedActorSystemErr
197
202
198
203
// === lock ----------------------------------------------------------------
199
204
205
+ @available ( SwiftStdlib 5 . 7 , * )
200
206
fileprivate class _Lock {
201
207
#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
202
208
private let underlying : UnsafeMutablePointer < os_unfair_lock >
0 commit comments