Dex.Future¶
- Subclasses:
Dex.AsyncPair
,Dex.Block
,Dex.Cancellable
,Dex.Delayed
,Dex.Fiber
,Dex.FutureSet
,Dex.Promise
,Dex.StaticFuture
,Dex.Timeout
,Dex.UnixSignal
Methods¶
- Inherited:
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
class |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
None
Fields¶
None
Class Details¶
- class Dex.Future¶
- Bases:
- Abstract:
No
Dex.Future
is the base class representing a future which may resolve with a value or reject with error at some point in the future.It is the basis for libdex’s concurrency and parallelism model.
Use futures to represent work in progress and allow consumers to build robust processing chains up front which will complete or fail as futures resolve or reject.
When running on a
Dex.Fiber
, you may useDex.Future.await_
() and similar functions to suspend the current thread and return upon completion of the dependent future.- classmethod all(futures)¶
- Parameters:
futures ([
Dex.Future
]) – an array of futures- Returns:
- Return type:
Creates a new
Dex.Future
that resolves when all futures resolve.The resulting
Dex.Future
will not resolve or reject until all futures have either resolved or rejected.
- classmethod all_race(futures)¶
- Parameters:
futures ([
Dex.Future
]) – an array of futures- Returns:
- Return type:
Creates a new
Dex.Future
that resolves when all futures resolve.If any future rejects, the resulting
Dex.Future
also rejects immediately.
- classmethod any(futures)¶
- Parameters:
futures ([
Dex.Future
]) – an array of futures- Returns:
- Return type:
Creates a new
Dex.Future
that resolves when the first future resolves.If all futures reject, then the
Dex.Future
returned will also reject.
- classmethod catch(future, callback, *callback_data)¶
- Parameters:
future (
Dex.Future
) – aDex.Future
callback (
Dex.FutureCallback
) – a callback to execute
- Returns:
- Return type:
Calls callback when future rejects.
If future resolves, then callback will not be called.
- classmethod catch_loop(future, callback, *callback_data)¶
- Parameters:
future (
Dex.Future
) – aDex.Future
callback (
Dex.FutureCallback
) – a callback to execute
- Returns:
- Return type:
Asynchronously calls callback when future rejects.
This is similar to
Dex.Future.catch
() except that it will call callback multiple times as each returnedDex.Future
rejects, allowing for infinite loops.
- classmethod finally_(future, callback, *callback_data)¶
- Parameters:
future (
Dex.Future
) – aDex.Future
callback (
Dex.FutureCallback
) – a callback to execute
- Returns:
- Return type:
Calls callback when future resolves or rejects.
- classmethod finally_loop(future, callback, *callback_data)¶
- Parameters:
future (
Dex.Future
) – aDex.Future
callback (
Dex.FutureCallback
) – a callback to execute
- Returns:
- Return type:
Asynchronously calls callback when future rejects or resolves.
This is similar to
Dex.Future.finally_
() except that it will call callback multiple times as each returnedDex.Future
rejects or resolves, allowing for infinite loops.
- classmethod first(futures)¶
- Parameters:
futures ([
Dex.Future
]) – an array of futures- Returns:
- Return type:
Creates a new
Dex.Future
that resolves or rejects as soon as the first dependent future resolves or rejects, sharing the same result.
- classmethod new_for_boolean(v_bool)¶
- Parameters:
v_bool (
bool
) – the resolved value for the future- Returns:
a resolved
Dex.Future
- Return type:
Creates a new
Dex.Future
and resolves it with v_bool.
- classmethod new_for_double(v_double)¶
- Parameters:
v_double (
float
) – the resolved value for the future- Returns:
a resolved
Dex.Future
- Return type:
Creates a new
Dex.Future
and resolves it with v_double.
- classmethod new_for_errno(errno_)¶
- Parameters:
errno (
int
) – theerrno
to use for rejection- Returns:
a rejected
Dex.Future
.- Return type:
Creates a new rejected future using errno_ as the value of errno for the
GLib.Error
.The resulting error domain will be %G_IO_ERROR.
New in version 0.4.
- classmethod new_for_error(error)¶
- Parameters:
error (
GLib.Error
) – aGLib.Error
- Returns:
- Return type:
Creates a read-only
Dex.Future
that has rejected.
- classmethod new_for_float(v_float)¶
- Parameters:
v_float (
float
) – the resolved value for the future- Returns:
a resolved
Dex.Future
- Return type:
Creates a new
Dex.Future
and resolves it with v_float.
- classmethod new_for_int(v_int)¶
- Parameters:
v_int (
int
) – the resolved value for the future- Returns:
a resolved
Dex.Future
- Return type:
Creates a new
Dex.Future
and resolves it with v_int.
- classmethod new_for_int64(v_int64)¶
- Parameters:
v_int64 (
int
) – the resolved value for the future- Returns:
a resolved
Dex.Future
- Return type:
Creates a new
Dex.Future
and resolves it with v_int64.
- classmethod new_for_object(value)¶
- Parameters:
value (
GObject.Object
) – the value- Returns:
a resolved
Dex.Future
- Return type:
Creates a new
Dex.Future
that is resolved with value.
- classmethod new_for_pointer(pointer)¶
- Parameters:
pointer (
object
orNone
) – the resolved future value as a pointer- Returns:
a resolved
Dex.Future
- Return type:
Creates a new
Dex.Future
that is resolved with pointer as aGObject.TYPE_POINTER
.
- classmethod new_for_string(string)¶
- Parameters:
string (
str
) – the resolved value for the future- Returns:
a resolved
Dex.Future
- Return type:
Creates a new
Dex.Future
and resolves it with string.
- classmethod new_for_uint(v_uint)¶
- Parameters:
v_uint (
int
) – the resolved value for the future- Returns:
a resolved
Dex.Future
- Return type:
Creates a new
Dex.Future
and resolves it with v_uint.
- classmethod new_for_uint64(v_uint64)¶
- Parameters:
v_uint64 (
int
) – the resolved value for the future- Returns:
a resolved
Dex.Future
- Return type:
Creates a new
Dex.Future
and resolves it with v_uint64.
- classmethod new_for_value(value)¶
- Parameters:
value (
GObject.Value
) – the resolvedGObject.Value
- Returns:
- Return type:
Creates a read-only
Dex.Future
that has resolved.
- classmethod new_infinite()¶
- Returns:
a
Dex.Future
that will never complete or reject- Return type:
Creates an infinite future that will never resolve or reject. This can be useful when you want to mock a situation of “run forever” unless another future rejects or resolves.
New in version 0.4.
- classmethod new_take_object(value)¶
- Parameters:
value (
GObject.Object
) – the value- Returns:
a resolved
Dex.Future
- Return type:
Creates a new
Dex.Future
that is resolved with value.
- classmethod new_take_string(string)¶
- Parameters:
string (
str
) – the resolved value for the future- Returns:
a resolved
Dex.Future
- Return type:
Creates a new
Dex.Future
and resolves it with string.
- classmethod then(future, callback, *callback_data)¶
- Parameters:
future (
Dex.Future
) – aDex.Future
callback (
Dex.FutureCallback
) – a callback to execute
- Returns:
- Return type:
Calls callback when future resolves.
If future rejects, then callback will not be called.
- classmethod then_loop(future, callback, *callback_data)¶
- Parameters:
future (
Dex.Future
) – aDex.Future
callback (
Dex.FutureCallback
) – a callback to execute
- Returns:
- Return type:
Asynchronously calls callback when future resolves.
This is similar to
Dex.Future.then
() except that it will call callback multiple times as each returnedDex.Future
resolves or rejects, allowing for infinite loops.
- await_()¶
-
Suspends the current
Dex.Fiber
and resumes when self has completed.If self is completed when this function is called, the fiber will handle the result immediately.
This function may only be called within a
Dex.Fiber
. To do otherwise will returnFalse
and error set toDex.Error.NO_FIBER
.It is an error to call this function in a way that would cause intermediate code to become invalid when resuming the stack. For example, if a foreach-style function taking a callback was to suspend from the callback, undefined behavior may occur such as thread-local-storage having changed.
- await_boolean()¶
- Raises:
- Returns:
- Return type:
Awaits on self and returns the
bool
result.If the result is not a
bool
, error is set.
- await_boxed()¶
- Raises:
- Returns:
the boxed result, or
None
and error is set.- Return type:
Awaits on self and returns the
GObject.TYPE_BOXED
based result.
- await_double()¶
- Raises:
- Returns:
an double, or 0 in case of failure and error is set.
- Return type:
Awaits on self and returns the result as an double.
The resolved value must be of type
GObject.TYPE_INT
or error is set.
- await_enum()¶
- Raises:
- Returns:
the enum or 0 and error is set.
- Return type:
Awaits on self and returns the enum result.
If the result is not a
GObject.TYPE_ENUM
, error is set.
- await_flags()¶
- Raises:
- Returns:
the flags or 0 and error is set.
- Return type:
Awaits on self and returns the flags result.
If the result is not a
GObject.TYPE_FLAGS
, error is set.
- await_float()¶
- Raises:
- Returns:
an float, or 0 in case of failure and error is set.
- Return type:
Awaits on self and returns the result as an float.
The resolved value must be of type
GObject.TYPE_INT
or error is set.
- await_int()¶
- Raises:
- Returns:
an int, or 0 in case of failure and error is set.
- Return type:
Awaits on self and returns the result as an int.
The resolved value must be of type
GObject.TYPE_INT
or error is set.
- await_int64()¶
- Raises:
- Returns:
an int64, or 0 in case of failure and error is set.
- Return type:
Awaits on self and returns the result as an int64.
The resolved value must be of type
GObject.TYPE_INT64
or error is set.
- await_object()¶
- Raises:
- Returns:
the object, or
None
and error is set.- Return type:
Awaits on self and returns the
GObject.Object
-based result.
- await_pointer()¶
- Raises:
- Returns:
a pointer or
None
- Return type:
Calls
Dex.Future.await_
() and returns the value ofGObject.Value.get_pointer
(), otherwise error is set if the future rejected.
- await_string()¶
- Raises:
- Returns:
the string or
None
and error is set- Return type:
Awaits on self and returns the string result.
If the result is not a
GObject.TYPE_STRING
, error is set.
- await_uint()¶
- Raises:
- Returns:
an uint, or 0 in case of failure and error is set.
- Return type:
Awaits on self and returns the result as an uint.
The resolved value must be of type
GObject.TYPE_INT
or error is set.
- await_uint64()¶
- Raises:
- Returns:
an uint64, or 0 in case of failure and error is set.
- Return type:
Awaits on self and returns the result as an uint64.
The resolved value must be of type
GObject.TYPE_INT64
or error is set.
- await_variant()¶
- Raises:
- Returns:
the variant result, or
None
and error is set.- Return type:
Awaits on self and returns the
GObject.TYPE_VARIANT
based result.New in version 0.4.
- disown()¶
Disowns a future, allowing it to run to completion even though there may be no observer interested in the futures completion or rejection.
New in version 0.4.
- get_status()¶
- Return type:
- get_value()¶
- Raises:
- Return type:
- is_pending()¶
-
This is a convenience function equivalent to calling
Dex.Future.get_status
() and checking forDex.FutureStatus.PENDING
.
- is_rejected()¶
-
This is a convenience function equivalent to calling
Dex.Future.get_status
() and checking forDex.FutureStatus.REJECTED
.
- is_resolved()¶
-
This is a convenience function equivalent to calling
Dex.Future.get_status
() and checking forDex.FutureStatus.RESOLVED
.