UNPKG

1.38 kBTypeScriptView Raw
1import { InspectionEvent } from "./inspection.js";
2import { ActorSystemInfo, AnyActorRef, Observer, EventObject, Subscription } from "./types.js";
3interface ScheduledEvent {
4 id: string;
5 event: EventObject;
6 startedAt: number;
7 delay: number;
8 source: AnyActorRef;
9 target: AnyActorRef;
10}
11export interface Clock {
12 setTimeout(fn: (...args: any[]) => void, timeout: number): any;
13 clearTimeout(id: any): void;
14}
15interface Scheduler {
16 schedule(source: AnyActorRef, target: AnyActorRef, event: EventObject, delay: number, id: string | undefined): void;
17 cancel(source: AnyActorRef, id: string): void;
18 cancelAll(actorRef: AnyActorRef): void;
19}
20export interface ActorSystem<T extends ActorSystemInfo> {
21 get: <K extends keyof T['actors']>(key: K) => T['actors'][K] | undefined;
22 inspect: (observer: Observer<InspectionEvent> | ((inspectionEvent: InspectionEvent) => void)) => Subscription;
23 scheduler: Scheduler;
24 getSnapshot: () => {
25 _scheduledEvents: Record<string, ScheduledEvent>;
26 };
27 start: () => void;
28 _clock: Clock;
29 _logger: (...args: any[]) => void;
30}
31export type AnyActorSystem = ActorSystem<any>;
32export declare function createSystem<T extends ActorSystemInfo>(rootActor: AnyActorRef, options: {
33 clock: Clock;
34 logger: (...args: any[]) => void;
35 snapshot?: unknown;
36}): ActorSystem<T>;
37export {};