It has a mailbox, can receive and process messages asynchronously
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
actors :: Actor :: defaultinit
pthreads :: Thread :: defaultinit
core :: Object :: defaultinit
core :: Finalizable :: defaultinit
core :: Finalizable :: finalize
Liberate any resources held byself
before the memory holding self
is freed
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: output_class_name
Display class name on stdout (debug only).
# 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