anthdm / hollywood

Blazingly fast and light-weight Actor engine written in Golang
MIT License
1.2k stars 101 forks source link

Ability to grab all PIDs in the registry #149

Open stevohuncho opened 9 months ago

stevohuncho commented 9 months ago

It would make things less complicated in my repos if I was able to have a couple more public functions for reading the registry. Right now only being able to get active PID info only by inputing the specific ID I'm looking for isn't too helpful for my case. I require the ability to check what the active PIDs are upon request. Using the event stream to monitor this just bloats my code by needing to create my own mapping to just replicate the privated one. I understand it is privated for mutex reasons, but if these functions could be added it would be very helpful. I have used these functions in my own code before using my fork with no issues, but I think this could be useful to others as well.

registry.go

...

func (r *Registry) GetIDs() []string {
    r.mu.RLock()
    defer r.mu.RUnlock()
    keys := make([]string, 0, len(r.lookup))
    for k := range r.lookup {
        keys = append(keys, k)
    }
    return keys
}

func (r *Registry) GetPIDs() []*PID {
    r.mu.RLock()
    defer r.mu.RUnlock()
    keys := make([]*PID, 0, len(r.lookup))
    for _, v := range r.lookup {
        keys = append(keys, v.PID())
    }
    return keys
}

...
anthdm commented 9 months ago

Makes sense. Let me think about this today and come up with some stuff for you.

webfrank commented 2 months ago

It would be a very useful addition, also a Lookup function to search for an ID