Getting live Actors of a given class without DeadActorError
Opened this issue · 0 comments
andy-twosticks commented
I keep finding I need to retreive actors that are alive and of a given class -- normally just to count them.
What's the correct way of doing this without getting a DeadActorError?
The obvious doesn't work:
Celluloid::Actor.all.select{|a| a.alive? && a.is_a?(Thing)}
Maybe this is because of a race condition -- alive?
is true when the first part of the test happens, but false when we reach the second part? But I don't know for sure.
The only workable solutions I have been able to find are:
Celluloid::Actor.all.select{|a| a.alive? && a.__klass__ == "Thing"}
Which seems to rely on a private method, so I'm not very happy about that.
Or I could trap for DeadActorError, which seems worse...
Proposed solution should there not already be one:
Make alive?
a valid method to call on a dead Actor, rather than raising a NoMethodError as it does now...