Remote Procedure Calls
Remote procedure calls (RPC) are how clients communicate with actors. RPCs are as simple as writing a method on the actor class and then calling it from the client.
Writing RPCs
export class Example extends Actor {
// This is an RPC
multiplyByTwo(rpc: Rpc<Example>, x: number) {
return x * 2;
}
}Private Methods
export default class Example extends Actor {
// This is private and cannot be called by clients
#calcFibonacci(n: number): number {
if (n <= 1) return n;
return this.#calcFibonacci(n - 1) + this.#calcFibonacci(n - 2);
}
// This is public and can be called by clients
fetchFibonacci(rpc: Rpc<Example>, n: number): number {
return this.#calcFibonacci(n);
}
}Streaming Return Data
Calling RPCs
Type Safety
Error Handling
User Errors
Internal Errors
Schema Validation
Authentication
Last updated