actors :: Future :: defaultinit
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: Object :: defaultinit
actors :: Future :: defaultinit
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).
# The promise of a value which will be set asynchronously
class Future[E]
# Value promised by `self`
var value: nullable E = null
# Mutex for synchronisation
protected var mutex = new Mutex
# Condition variable for synchronisation
protected var cond: nullable PthreadCond = null
# Can be used to check if the value is available without waiting
protected var is_done = false
# Set the value and signal so that, someone waiting for `value` can retrieve it
fun set_value(value: E) do
mutex.lock
is_done = true
self.value = value
var cond = self.cond
if cond != null then cond.signal
mutex.unlock
end
# Return immediatly if `value` is set, or block waiting for `value` to be set
fun join: E do
mutex.lock
if not is_done then
var cond = self.cond
if cond == null then
cond = new PthreadCond
self.cond = cond
end
cond.wait(mutex)
end
mutex.unlock
return value
end
end
lib/actors/actors.nit:168,1--206,3