actors :: Actor :: defaultinit
# Abstraction of an actor
# It has a mailbox, can receive and process messages asynchronously
abstract class Actor
super Thread
# Type of the proxied class (or working class)
type V: Object
# The instance used to do the real work
# i.e. the real working object
var instance: V
# Mailbox used to receive and process messages
var mailbox = new Mailbox[Message].with_actor(self)
# Is `self` working ?
# i.e. does it have messages to process or is it processing one now ?
var working = true
redef fun main do
loop
var m = mailbox.shift
if m isa ShutDownMessage then
sys.active_actors.decrement
return null
end
m.invoke(instance)
end
end
# Ends `self`, cancel ongoing work abrutly
# Pretty dangerous to use
fun kill do
var n = self.native
if n != null then n.cancel
end
end
lib/actors/actors.nit:24,1--60,3