Skip to content

Commit

Permalink
added GetPID to registry
Browse files Browse the repository at this point in the history
  • Loading branch information
anthdm committed Dec 30, 2023
1 parent ac25f94 commit 0289914
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions actor/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 10 additions & 0 deletions actor/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 0289914

Please sign in to comment.