Skip to content

Commit 5d90a69

Browse files
authored
Merge pull request #61542 from ktoso/wip-more-docs-on-decoder-da
[Distributed] More docs on the InvocationDecoder itself
2 parents dec8813 + e1527ff commit 5d90a69

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

stdlib/public/Distributed/DistributedActorSystem.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,27 @@ public struct RemoteCallArgument<Value> {
849849
/// /// performs the actual distributed (local) instance method invocation.
850850
/// mutating func decodeNextArgument<Argument: SerializationRequirement>() throws -> Argument
851851
/// ```
852+
///
853+
/// ### Decoding DistributedActor arguments using Codable
854+
/// When using an actor system where ``ActorID`` is ``Codable``, every distributed actor using that system
855+
/// is also implicitly ``Codable`` (see ``DistributedActorSystem``). Such distributed actors are encoded
856+
/// as their ``ActorID`` stored in an ``Encoder/singleValueContainer``. When ``Codable`` is being used
857+
/// by such a system, the ``decodeNextArgument`` method will be using ``Decoder`` to
858+
/// decode the incoming values, which may themselves be distributed actors.
859+
///
860+
/// An actor system must be provided to the ``Decoder`` in order for a distributed actor's ``Decodable/init(from:)``
861+
/// to be able to return the instance of the actor. Specifically, the decoded``ActorID`` is passed to the actor system's `resolve(id:as:)` method in order to
862+
/// return either a local instance identified by this ID, or creating a remote actor reference.
863+
/// Thus, you must set the actor system the decoding is performed for, on the decoder's `userInfo`, as follows:
864+
///
865+
/// ```
866+
/// mutating func decodeNextArgument<Argument: SerializationRequirement>() throws -> Argument {
867+
/// let argumentData: Data = /// ...
868+
/// // ...
869+
/// decoder.userInfo[.actorSystemKey] = self.actorSystem
870+
/// return try Argument.decode(
871+
/// }
872+
/// ```
852873
@available(SwiftStdlib 5.7, *)
853874
public protocol DistributedTargetInvocationDecoder {
854875
/// The serialization requirement that the types passed to `decodeNextArgument` are required to conform to.

0 commit comments

Comments
 (0)