diff --git a/actor/engine_test.go b/actor/engine_test.go index 6eed2d0..8f0e327 100644 --- a/actor/engine_test.go +++ b/actor/engine_test.go @@ -36,6 +36,16 @@ func newTickReceiver(wg *sync.WaitGroup) Producer { } } +func TestRegistryGetPID(t *testing.T) { + e, _ := NewEngine(nil) + expectedPID1 := e.SpawnFunc(func(c *Context) {}, "foo", WithID("1")) + expectedPID2 := e.SpawnFunc(func(c *Context) {}, "foo", WithID("2")) + pid := e.Registry.GetPID("foo", "1") + assert.True(t, pid.Equals(expectedPID1)) + pid = e.Registry.GetPID("foo", "2") + assert.True(t, pid.Equals(expectedPID2)) +} + func TestSendToNilPID(t *testing.T) { e, _ := NewEngine(nil) e.Send(nil, "foo") diff --git a/actor/registry.go b/actor/registry.go index b9d8e04..0bf5869 100644 --- a/actor/registry.go +++ b/actor/registry.go @@ -19,6 +19,16 @@ func newRegistry(e *Engine) *Registry { } } +// GetPID returns the process id associated for the given kind and its id. +// GetPID returns nil if the process was not found. +func (r *Registry) GetPID(kind, id string) *PID { + proc := r.getByID(kind + pidSeparator + id) + if proc != nil { + return proc.PID() + } + return nil +} + // Remove removes the given PID from the registry. func (r *Registry) Remove(pid *PID) { r.mu.Lock()