Skip to content

akbashev/cluster-virtual-actors

Repository files navigation

Cluster System Virtual Actors

Virtual actors framework implementation for Swift Cluster System.

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
)

About

Virtual actors for Swift's Cluster Systems

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages