Skip to content

Commit 1f840d7

Browse files
committed
actor system docs
1 parent 2418aeb commit 1f840d7

File tree

2 files changed

+269
-13
lines changed

2 files changed

+269
-13
lines changed

stdlib/public/Distributed/DistributedActor.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ import _Concurrency
101101
/// It is possible to explicitly declare an parameter-free initializer (`init()`),
102102
/// however the `actorSystem` property still must be assigned a concrete actor
103103
/// system instance the actor shall be part of.
104-
104+
///
105105
/// In general it is recommended to always have an `actorSystem` parameter as
106106
/// the last non-defaulted non-closure parameter in every distributed actors
107107
/// initializer parameter list. This way it is simple to swap in a "test actor
@@ -224,10 +224,13 @@ public protocol DistributedActor: AnyActor, Identifiable, Hashable
224224

225225
@available(SwiftStdlib 5.7, *)
226226
extension DistributedActor {
227+
228+
/// A distributed actor's hash and equality is implemented by directly delegating to it's ``id``.
227229
nonisolated public func hash(into hasher: inout Hasher) {
228230
self.id.hash(into: &hasher)
229231
}
230232

233+
/// A distributed actor's hash and equality is implemented by directly delegating to it's ``id``.
231234
nonisolated public static func ==(lhs: Self, rhs: Self) -> Bool {
232235
lhs.id == rhs.id
233236
}
@@ -249,6 +252,18 @@ extension CodingUserInfoKey {
249252

250253
@available(SwiftStdlib 5.7, *)
251254
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.
252267
nonisolated public init(from decoder: Decoder) throws {
253268
guard let system = decoder.userInfo[.actorSystemKey] as? ActorSystem else {
254269
throw DistributedActorCodingError(message:
@@ -263,6 +278,8 @@ extension DistributedActor /*: implicitly Decodable */ where Self.ID: Decodable
263278

264279
@available(SwiftStdlib 5.7, *)
265280
extension DistributedActor /*: implicitly Encodable */ where Self.ID: Encodable {
281+
282+
/// Encodes the ``actor.id`` as a single value into the passed `encoder`.
266283
nonisolated public func encode(to encoder: Encoder) throws {
267284
var container = encoder.singleValueContainer()
268285
try container.encode(self.id)

0 commit comments

Comments
 (0)