Contents

akbashev/cluster-virtual-actors

Virtual actors for Swift's Cluster Systems

Usage

Documentation: TODO

  1. Install plugins. ClusterVirtualActorsPlugin wraps store into singleton, so singleton plugin also should be added (and order is important!).
let node = await ClusterSystem("simple-node") {
    $0.plugins.install(plugin: ClusterSingletonPlugin())
    $0.plugins.install(plugin: ClusterVirtualActorsPlugin())
}
  1. Make distributed actor VirtualActor and provide virtualID:
distributed actor SomeActor: VirtualActor {
    public static func spawn(on system: DistributedCluster.ClusterSystem, dependency: any Sendable & Codable) async throws -> SomeActor {
        /// A bit of boilerplate to check type until (associated type error)[https://github.com/swiftlang/swift/issues/74769] is fixed
        guard let dependency = dependency as? Dependency else { throw VirtualActorError.spawnDependencyTypeMismatch }
        return SomeActor(actorSystem: system, dependency: dependency)
    }
}
  1. Call the actor when needed:
let actor = try await self.actorSystem.virtualActors.getActor(
    identifiedBy: someId,
    dependency: dependency
)

Package Metadata

Repository: akbashev/cluster-virtual-actors

Stars: 4

Forks: 0

Open issues: 0

Default branch: main

Primary language: swift

License: Apache-2.0

README: README.md