The promise of a value which will be set asynchronously

Introduced properties

protected fun cond: nullable PthreadCond

actors :: Future :: cond

Condition variable for synchronisation
protected fun cond=(cond: nullable PthreadCond)

actors :: Future :: cond=

Condition variable for synchronisation
protected fun is_done: Bool

actors :: Future :: is_done

Can be used to check if the value is available without waiting
protected fun is_done=(is_done: Bool)

actors :: Future :: is_done=

Can be used to check if the value is available without waiting
fun join: E

actors :: Future :: join

Return immediatly if value is set, or block waiting for value to be set
protected fun mutex: Mutex

actors :: Future :: mutex

Mutex for synchronisation
protected fun mutex=(mutex: Mutex)

actors :: Future :: mutex=

Mutex for synchronisation
fun set_value(value: E)

actors :: Future :: set_value

Set the value and signal so that, someone waiting for value can retrieve it
fun value: nullable E

actors :: Future :: value

Value promised by self
protected fun value=(value: nullable E)

actors :: Future :: value=

Value promised by self

Redefined properties

redef type SELF: Future[E]

actors $ Future :: SELF

Type of this instance, automatically specialized in every class

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
protected fun cond: nullable PthreadCond

actors :: Future :: cond

Condition variable for synchronisation
protected fun cond=(cond: nullable PthreadCond)

actors :: Future :: cond=

Condition variable for synchronisation
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
protected fun is_done: Bool

actors :: Future :: is_done

Can be used to check if the value is available without waiting
protected fun is_done=(is_done: Bool)

actors :: Future :: is_done=

Can be used to check if the value is available without waiting
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
fun join: E

actors :: Future :: join

Return immediatly if value is set, or block waiting for value to be set
protected fun mutex: Mutex

actors :: Future :: mutex

Mutex for synchronisation
protected fun mutex=(mutex: Mutex)

actors :: Future :: mutex=

Mutex for synchronisation
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
fun set_value(value: E)

actors :: Future :: set_value

Set the value and signal so that, someone waiting for value can retrieve it
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
fun value: nullable E

actors :: Future :: value

Value promised by self
protected fun value=(value: nullable E)

actors :: Future :: value=

Value promised by self
package_diagram actors::Future Future core::Object Object actors::Future->core::Object

Parents

interface Object

core :: Object

The root of the class hierarchy.

Class definitions

actors $ Future
# 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