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  | 
  | 
class  | 
  | 
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
|
  | 
Virtual Methods¶
None
Fields¶
None
Class Details¶
- class Dex.Future¶
 - Bases:
 - Abstract:
 No
Dex.Futureis 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.Futurethat resolves when all futures resolve.The resulting
Dex.Futurewill 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.Futurethat resolves when all futures resolve.If any future rejects, the resulting
Dex.Futurealso rejects immediately.
- classmethod any(futures)¶
 - Parameters:
 futures ([
Dex.Future]) – an array of futures- Returns:
 - Return type:
 
Creates a new
Dex.Futurethat resolves when the first future resolves.If all futures reject, then the
Dex.Futurereturned will also reject.
- classmethod catch(future, callback, *callback_data)¶
 - Parameters:
 future (
Dex.Future) – aDex.Futurecallback (
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.Futurecallback (
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.Futurerejects, allowing for infinite loops.
- classmethod finally_(future, callback, *callback_data)¶
 - Parameters:
 future (
Dex.Future) – aDex.Futurecallback (
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.Futurecallback (
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.Futurerejects or resolves, allowing for infinite loops.
- classmethod first(futures)¶
 - Parameters:
 futures ([
Dex.Future]) – an array of futures- Returns:
 - Return type:
 
Creates a new
Dex.Futurethat 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.Futureand 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.Futureand resolves it with v_double.
- classmethod new_for_errno(errno_)¶
 - Parameters:
 errno (
int) – theerrnoto 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.Futurethat has rejected.
- classmethod new_for_fd(fd)¶
 - Parameters:
 fd (
int) – the file-descriptor to take ownership of- Returns:
 a resolved
Dex.Future- Return type:
 
Creates a new future that resolves to fd.
This function takes ownership of fd.
- 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.Futureand 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.Futureand 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.Futureand 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.Futurethat is resolved with value.
- classmethod new_for_pointer(pointer)¶
 - Parameters:
 pointer (
objectorNone) – the resolved future value as a pointer- Returns:
 a resolved
Dex.Future- Return type:
 
Creates a new
Dex.Futurethat 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.Futureand 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.Futureand 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.Futureand 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.Futurethat has resolved.
- classmethod new_infinite()¶
 - Returns:
 a
Dex.Futurethat 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.ObjectorNone) – the value- Returns:
 a resolved
Dex.Future- Return type:
 
Creates a new
Dex.Futurethat 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.Futureand resolves it with string.
- classmethod then(future, callback, *callback_data)¶
 - Parameters:
 future (
Dex.Future) – aDex.Futurecallback (
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.Futurecallback (
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.Futureresolves or rejects, allowing for infinite loops.
- await_()¶
 - 
Suspends the current
Dex.Fiberand 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 returnFalseand 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
boolresult.If the result is not a
bool, error is set.
- await_boxed()¶
 - Raises:
 - Returns:
 the boxed result, or
Noneand error is set.- Return type:
 
Awaits on self and returns the
GObject.TYPE_BOXEDbased 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_DOUBLEor 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_fd()¶
 - Raises:
 - Returns:
 a valid file descriptor or -1. you may get -1 without error being set if there was no rejected future.
- Return type:
 
Awaits on self and returns the resultint file-descriptor.
The resolved value must be of type %DEX_TYPE_FD or 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_FLOATor 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_INTor 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_INT64or error is set.
- await_object()¶
 - Raises:
 - Returns:
 the object, or
Noneand 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
Noneand 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_UINTor 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_UINT64or error is set.
- await_variant()¶
 - Raises:
 - Returns:
 the variant result, or
Noneand error is set.- Return type:
 
Awaits on self and returns the
GObject.TYPE_VARIANTbased 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.