@@ -20,24 +20,11 @@ import Glibc
2020import WinSDK
2121#endif
2222
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.
4128@available ( SwiftStdlib 5 . 7 , * )
4229public final class LocalTestingDistributedActorSystem : DistributedActorSystem , @unchecked Sendable {
4330 public typealias ActorID = LocalTestingActorAddress
@@ -86,9 +73,6 @@ public final class LocalTestingDistributedActorSystem: DistributedActorSystem, @
8673 }
8774
8875 public func resignID( _ id: ActorID ) {
89- guard self . assignedIDsLock. withLock ( { self . assignedIDs. contains ( id) } ) else {
90- fatalError ( " Attempted to resign unknown id ' \( id) ' " )
91- }
9276 self . activeActorsLock. withLock {
9377 self . activeActors. removeValue ( forKey: id)
9478 }
@@ -109,7 +93,7 @@ public final class LocalTestingDistributedActorSystem: DistributedActorSystem, @
10993 Act. ID == ActorID ,
11094 Err: Error ,
11195 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 " )
11397 }
11498
11599 public func remoteCallVoid< Act, Err> (
@@ -121,7 +105,7 @@ public final class LocalTestingDistributedActorSystem: DistributedActorSystem, @
121105 where Act: DistributedActor ,
122106 Act. ID == ActorID ,
123107 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 " )
125109 }
126110
127111 private struct ActorIDProvider {
@@ -140,6 +124,26 @@ public final class LocalTestingDistributedActorSystem: DistributedActorSystem, @
140124 }
141125}
142126
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 , * )
143147public struct LocalTestingInvocationEncoder : DistributedTargetInvocationEncoder {
144148 public typealias SerializationRequirement = Codable
145149
@@ -164,7 +168,8 @@ public struct LocalTestingInvocationEncoder: DistributedTargetInvocationEncoder
164168 }
165169}
166170
167- public class LocalTestingInvocationDecoder : DistributedTargetInvocationDecoder {
171+ @available ( SwiftStdlib 5 . 7 , * )
172+ public final class LocalTestingInvocationDecoder : DistributedTargetInvocationDecoder {
168173 public typealias SerializationRequirement = Codable
169174
170175 public func decodeGenericSubstitutions( ) throws -> [ Any . Type ] {
@@ -197,6 +202,7 @@ public struct LocalTestingDistributedActorSystemError: DistributedActorSystemErr
197202
198203// === lock ----------------------------------------------------------------
199204
205+ @available ( SwiftStdlib 5 . 7 , * )
200206fileprivate class _Lock {
201207 #if os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
202208 private let underlying : UnsafeMutablePointer < os_unfair_lock >
0 commit comments