import { PID } from "./pid" ; import { IProcess } from "./process" ; export type IProcessResolver = ( pid : PID ) => IProcess ; export class ProcessRegistry { private localActorRefs : { [ Id ] : any ; } = { } ; private counter = 0 ; private hostResolvers : IProcessResolver [ ] = [ ] ; public Address = "nonhost" ; Get ( pid ) { if ( pid . Address != "nonhost" && pid . Address != this . Address ) { for ( let resolver of this . hostResolvers ) { let ref = resolver ( pid ) ; if ( ref ) { return ref ; } } throw "Unknown host" ; } return this . localActorRefs [ pid . Id ] ; } TryAdd ( id , ref ) { var pid = new PID ( this . Address , id ) ; this . localActorRefs [ pid . Id ] = ref ; return pid ; } NextId ( ) { return "$" + this . counter ++ ; } Remove ( pid ) { this . localActorRefs [ pid . Id ] = undefined ; } RegisterHostResolver ( resolver ) { this . hostResolvers . push ( resolver ) ; } } const processRegistry = new ProcessRegistry ( ) ; export default processRegistry ;