@@ -101,7 +101,7 @@ import _Concurrency
101
101
/// It is possible to explicitly declare an parameter-free initializer (`init()`),
102
102
/// however the `actorSystem` property still must be assigned a concrete actor
103
103
/// system instance the actor shall be part of.
104
-
104
+ ///
105
105
/// In general it is recommended to always have an `actorSystem` parameter as
106
106
/// the last non-defaulted non-closure parameter in every distributed actors
107
107
/// initializer parameter list. This way it is simple to swap in a "test actor
@@ -224,10 +224,13 @@ public protocol DistributedActor: AnyActor, Identifiable, Hashable
224
224
225
225
@available ( SwiftStdlib 5 . 7 , * )
226
226
extension DistributedActor {
227
+
228
+ /// A distributed actor's hash and equality is implemented by directly delegating to it's ``id``.
227
229
nonisolated public func hash( into hasher: inout Hasher ) {
228
230
self . id. hash ( into: & hasher)
229
231
}
230
232
233
+ /// A distributed actor's hash and equality is implemented by directly delegating to it's ``id``.
231
234
nonisolated public static func == ( lhs: Self , rhs: Self ) -> Bool {
232
235
lhs. id == rhs. id
233
236
}
@@ -249,6 +252,18 @@ extension CodingUserInfoKey {
249
252
250
253
@available ( SwiftStdlib 5 . 7 , * )
251
254
extension DistributedActor /*: implicitly Decodable */ where Self. ID: Decodable {
255
+
256
+ /// Initializes an instance of this distributed actor by decoding its ``id``,
257
+ /// and passing it to the ``DistributedActorSystem`` obtained from `decoder.userInfo[`actorSystemKey]`.
258
+ ///
259
+ /// ## Requires: The decoder must have the ``CodingUserInfoKey/actorSystemKey`` set to
260
+ /// the ``ActorSystem`` that this actor expects, as it will be used to call ``DistributedActor/resolve(id:using:)``
261
+ /// on, in order to obtain the instance this initializer should return.
262
+ ///
263
+ /// - Parameter decoder: used to decode the ``ID`` of this distributed actor.
264
+ /// - Throws: If the actor system value in `decoder.userInfo` is missing, or mis-typed;
265
+ /// the `ID` fails to decode from the passed `decoder`;
266
+ // or if the ``DistributedActor/resolve(id:using:)`` method invoked by this initializer throws.
252
267
nonisolated public init ( from decoder: Decoder ) throws {
253
268
guard let system = decoder. userInfo [ . actorSystemKey] as? ActorSystem else {
254
269
throw DistributedActorCodingError ( message:
@@ -263,6 +278,8 @@ extension DistributedActor /*: implicitly Decodable */ where Self.ID: Decodable
263
278
264
279
@available ( SwiftStdlib 5 . 7 , * )
265
280
extension DistributedActor /*: implicitly Encodable */ where Self. ID: Encodable {
281
+
282
+ /// Encodes the ``actor.id`` as a single value into the passed `encoder`.
266
283
nonisolated public func encode( to encoder: Encoder ) throws {
267
284
var container = encoder. singleValueContainer ( )
268
285
try container. encode ( self . id)
0 commit comments