ProtocolDistributed5.9.0
DistributedActor
The such obtained actor system is then used to resolve(id:using:)
the decoded ID
.
- iOS
- 16.0+
- macOS
- 13.0+
- tvOS
- 16.0+
- watchOS
- 9.0+
protocol DistributedActor : Hashable, Identifiable, AnyActor
Use the CodingUserInfoKey.actorSystemKey
to provide the necessary actor system for the decoding initializer when decoding a distributed actor.
Supertypes
protocol AnyActor
Common marker protocol providing a shared “base” for both (local)
Actor
and (potentially remote)DistributedActor
types.protocol Equatable
A type that can be compared for value equality.
protocol Hashable
A type that can be hashed into a
Hasher
to produce an integer hash value.protocol Identifiable
A class of types whose instances hold the value of an entity with stable identity.
protocol Sendable
A type whose values can safely be passed across concurrency domains by copying.
Requirements
associatedtype ActorSystem : DistributedActorSystem
The type of transport used to communicate with actors of this type.
associatedtype SerializationRequirement
The serialization requirement to apply to all distributed declarations inside the actor.
static func resolve(id: Self.ID, using: Self.ActorSystem
) throws -> Self Resolves the passed in
id
against thesystem
, returning either a local or remote actor reference.var actorSystem: Self.ActorSystem
The
DistributedActorSystem
that is managing this distributed actor.var id: Self.ID
Logical identity of this distributed actor.
var unownedExecutor: UnownedSerialExecutor
Retrieve the executor for this distributed actor as an optimized, unowned reference. This API is equivalent to
Actor.unownedExecutor
, however, by default, it intentionally returnsnil
if this actor is a reference to a remote distributed actor, because the executor for remote references is effectively never g
Citizens in Distributed
Members
static func == (Self, Self
) -> Bool A distributed actor’s hash and equality is implemented by directly delegating to its
id
.func assertIsolated(() -> String, file: StaticString, line: UInt
) Performs an executor check in debug builds.
func assumeIsolated<T>((isolated Self) throws -> T, file: StaticString, line: UInt
) rethrows -> T Assume that the current actor is a local distributed actor and that the currently executing context is the same as that actors serial executor, or crash.
func hash(into: inout Hasher
) A distributed actor’s hash and equality is implemented by directly delegating to its
id
.func preconditionIsolated(() -> String, file: StaticString, line: UInt
) Unconditionally if the current task is executing on the serial executor of the passed in
actor
, and if not crash the program offering information about the executor mismatch.func whenLocal<T>((isolated Self) async throws -> T
) async rethrows -> T? Executes the passed ‘body’ only when the distributed actor is local instance.
Citizens in Distributed
where Self.ID:Encodable
Members
func encode(to: Encoder
) throws Encodes the
actor.id
as a single value into the passedencoder
.
Citizens in Distributed
where Self.ID:Decodable