Methods and structures dealing with Eina_Future. More...
Modules | |
Eina Future Callbacks | |
Methods and structures dealing with Eina_Future callbacks. | |
Data Structures | |
struct | _Eina_Future_Race_Result |
The struct that is used to store the race result. More... | |
struct | Eina_Future |
An opaque structure representing a callback to be called when a promise is fulfilled. More... | |
struct | _Eina_Future_Desc |
A struct used to define a callback and data for a future. More... | |
Typedefs | |
typedef struct _Eina_Future_Desc | Eina_Future_Desc |
Convenience wrapper over _Eina_Future_Desc. | |
typedef struct _Eina_Future_Race_Result | Eina_Future_Race_Result |
Convenience wrapper over _Eina_Future_Race_Result. | |
Variables | |
EINA_API const Eina_Value_Struct_Desc * | EINA_PROMISE_RACE_STRUCT_DESC |
A pointer to the race struct description, which is used by eina_promise_race_array(). More... | |
Methods and structures dealing with Eina_Future.
#define EINA_FUTURE_SENTINEL ((void *)(unsigned long)-1) |
Used by eina_promise_race_array() and eina_promise_all_array() and friends to flag the end of the array.
#define eina_promise_race | ( | ... | ) | eina_promise_race_array((Eina_Future *[]){__VA_ARGS__, EINA_FUTURE_SENTINEL}) |
A syntactic sugar over eina_promise_race_array().
Usage:
#define eina_future_race | ( | ... | ) | eina_future_race_array((Eina_Future *[]){__VA_ARGS__, EINA_FUTURE_SENTINEL}) |
A syntactic sugar over eina_future_race_array().
Usage:
#define eina_future_all | ( | ... | ) | eina_future_all_array((Eina_Future *[]){__VA_ARGS__, EINA_FUTURE_SENTINEL}) |
A syntactic sugar over eina_future_all_array().
Usage:
#define eina_promise_all | ( | ... | ) | eina_promise_all_array((Eina_Future *[]){__VA_ARGS__, EINA_FUTURE_SENTINEL}) |
A syntactic sugar over eina_promise_all_array().
Usage:
#define eina_future_cb_easy | ( | ... | ) | eina_future_cb_easy_from_desc((Eina_Future_Cb_Easy_Desc){__VA_ARGS__}) |
A syntactic sugar over eina_future_cb_easy_from_desc().
Usage:
#define eina_future_chain | ( | _prev, | |
... | |||
) | eina_future_chain_array(_prev, (Eina_Future_Desc[]){__VA_ARGS__, {.cb = NULL, .data = NULL}}) |
A syntactic sugar over eina_future_chain_array().
Usage:
#define eina_future_then | ( | _prev, | |
... | |||
) | eina_future_then_from_desc(_prev, (Eina_Future_Desc){__VA_ARGS__}) |
A syntactic sugar over eina_future_then_from_desc().
Usage:
#define eina_future_cb_console | ( | ... | ) | eina_future_cb_console_from_desc((Eina_Future_Cb_Console_Desc){__VA_ARGS__}) |
A syntactic sugar over eina_future_cb_console_from_desc().
Usage:
#define eina_future_cb_log_dbg | ( | _prefix, | |
_suffix | |||
) |
A syntactic sugar over eina_future_cb_log_from_desc().
This macro will set the following fields of the Eina_Future_Cb_Log_Desc:
__FILE__
function will be used. __func__
macro will be used. EINA_LOG_LEVEL_DBG
will be used. EINA_LOG_DOMAIN_DEFAULT
will be used. __LINE__
macro will be used.Usage:
#define eina_future_cb_log_crit | ( | _prefix, | |
_suffix | |||
) |
A syntactic sugar over eina_future_cb_log_from_desc().
This macro will set the following fields of the Eina_Future_Cb_Log_Desc:
Usage:
#define eina_future_cb_log_err | ( | _prefix, | |
_suffix | |||
) |
A syntactic sugar over eina_future_cb_log_from_desc().
This macro will set the following fields of the Eina_Future_Cb_Log_Desc:
Usage:
#define eina_future_cb_log_info | ( | _prefix, | |
_suffix | |||
) |
A syntactic sugar over eina_future_cb_log_from_desc().
This macro will set the following fields of the Eina_Future_Cb_Log_Desc:
Usage:
#define eina_future_cb_log_warn | ( | _prefix, | |
_suffix | |||
) |
A syntactic sugar over eina_future_cb_log_from_desc().
This macro will set the following fields of the Eina_Future_Cb_Log_Desc:
Usage:
_prefix | PREFIX |
_suffix | SUFFIX |
#define eina_future_then_easy | ( | _prev, | |
... | |||
) | eina_future_then_from_desc(_prev, eina_future_cb_easy(__VA_ARGS__)) |
A syntactic sugar over eina_future_then() and eina_future_cb_easy().
Usage:
#define eina_future_chain_easy | ( | _prev, | |
... | |||
) | eina_future_chain_easy_array(_prev, (Eina_Future_Cb_Easy_Desc[]) {__VA_ARGS__, {NULL, NULL, NULL, NULL, NULL}}) |
A syntactic sugar over eina_future_chain() and eina_future_cb_easy().
Usage:
EINA_API void eina_future_cancel | ( | Eina_Future * | f | ) |
Cancels a future.
This function will cancel the whole future chain immediately (it will not be schedule to the next mainloop pass) and it will also cancel the promise linked against it. The Eina_Future_Cb will be called with an Eina_Value typed as EINA_VALUE_TYPE_ERROR, with its value set to ECANCELED
[in,out] | f | The future to cancel. |
EINA_API void eina_future_desc_flush | ( | Eina_Future_Desc * | desc | ) |
Flushes an Eina_Future_Desc.
This function is mainly used by bindings to flush an Eina_Future_Desc. It will call the Eina_Future_Cb with ENOMEM
and zero the desc
contents.
[in,out] | desc | The Eina_Future_Desc to flush, if NULL this is a noop. |
EINA_API void eina_future_cb_easy_desc_flush | ( | Eina_Future_Cb_Easy_Desc * | desc | ) |
Flushes an Eina_Future_Cb_Easy_Desc.
This function is mainly used by bindings to flush an Eina_Future_Cb_Easy_Desc. It will call the Eina_Future_Error_Cb with ENOMEM
, the Eina_Future_Free_Cb and zero the desc
contents.
[in,out] | desc | The Eina_Future_Cb_Easy_Desc to flush, if NULL this is a noop. |
References _Eina_Future_Cb_Easy_Desc::data, eina_value_flush(), _Eina_Future_Cb_Easy_Desc::error, and _Eina_Future_Cb_Easy_Desc::free.
EINA_API Eina_Value eina_promise_as_value | ( | Eina_Promise * | p | ) |
Creates a new Eina_Value from a promise.
This function creates a new Eina_Value that will store an Eina_Promise in it. This function is useful for dealing with promises inside an Eina_Future_Cb. By returning a promise inside the Eina_Value the whole chain will wait until the promise is resolved in order to continue its execution. Example:
[in,out] | p | The promise object to wrap in a value. |
NULL
.References DBG, EINA_SAFETY_ON_FALSE_GOTO, EINA_VALUE_EMPTY, eina_value_flush(), eina_value_pset(), eina_value_setup(), and EINA_VALUE_TYPE_PROMISE.
Referenced by eina_future_as_value().
EINA_API Eina_Value eina_future_as_value | ( | Eina_Future * | f | ) |
Creates an Eina_Value from a future.
This function is used for the same purposes as eina_promise_as_value(), but receives an Eina_Future instead.
[in,out] | f | A future to create a Eina_Value from. |
NULL
. f
will be CANCELED References DBG, eina_future_then, eina_promise_as_value(), eina_promise_new(), EINA_SAFETY_ON_NULL_GOTO, EINA_VALUE_EMPTY, EINA_VALUE_TYPE_PROMISE, and ERR.
EINA_API Eina_Future * eina_future_new | ( | Eina_Promise * | p | ) |
Creates a new future.
This function creates a new future and can be used to report that an operation has succeeded or failed using eina_promise_resolve() or eina_promise_reject().
Futures can also be canceled using eina_future_cancel(), which will cause the whole chain to be canceled alongside with any pending promise.
NULL
is returned) and the future attached to the promise will be canceled![in,out] | p | A promise used to attach a future. May not be NULL . |
NULL
on error. References _Eina_Future_Desc::cb, and EINA_SAFETY_ON_TRUE_GOTO.
Referenced by eina_future_all_array(), eina_future_all_iterator(), eina_future_race_array(), eina_future_rejected(), and eina_future_resolved().
EINA_API Eina_Future * eina_future_resolved | ( | Eina_Future_Scheduler * | scheduler, |
Eina_Value | value | ||
) |
Creates a new future that is already resolved to a value.
This function creates a new future with an already known value, that will be resolved and dispatched by the given scheduler
as usual.
This is a helper that behaves the same as eina_promise_new() followed by eina_future_new() and then eina_promise_resolve().
Futures can also be canceled using eina_future_cancel(), which will cause the whole chain to be canceled alongside with any pending promise.
[in,out] | scheduler | The scheduler to use. |
[in] | value | The value to be delivered. Note that the value contents must survive this function scope, that is, do not use stack allocated blobs, arrays, structures or types that keep references to memory you give. Values will be automatically cleaned up using eina_value_flush() once they are unused (no more future or futures returned a new value). |
NULL
on error.References eina_future_new(), eina_promise_new(), eina_promise_resolve(), EINA_SAFETY_ON_NULL_GOTO, and eina_value_flush().
EINA_API Eina_Future * eina_future_rejected | ( | Eina_Future_Scheduler * | scheduler, |
Eina_Error | err | ||
) |
Creates a new future that is already rejected to a specified error.
This function creates a new future with an already known error, that will be resolved and dispatched by the given scheduler
as usual.
This is a helper that behaves the same as eina_promise_new() followed by eina_future_new() and then eina_promise_reject().
Futures can also be canceled using eina_future_cancel(), which will cause the whole chain to be canceled alongside with any pending promise.
[in,out] | scheduler | The scheduler to use. |
[in] | err | An Eina_Error value |
NULL
on error.References eina_future_new(), eina_promise_new(), eina_promise_reject(), and EINA_SAFETY_ON_NULL_GOTO.
EINA_API Eina_Future * eina_future_then_from_desc | ( | Eina_Future * | prev, |
const Eina_Future_Desc | desc | ||
) |
Register an Eina_Future_Desc to be used when the future is resolved/rejected.
With this function a callback and data is attached to the future and then once it's resolved or rejected the callback will be informed.
If during the future creation an error happens this function will return NULL
, and the Eina_Future_Desc::cb will be called reporting an error (EINVAL
or ENOMEM
), so the user has a chance to free Eina_Future_Desc::data.
In case a future in the chain is canceled, the whole chain will be canceled immediately and the error ECANCELED
will be reported.
Here's a simple usage of this function.
Although the code presented at _size_ready()
is very simple, most of it is just used to check the Eina_Value type. In order to avoid this type of code the function eina_future_cb_easy_from_desc() was created. Please, check its documentation for more information.
This function can also be used to create a future chain, making it possible to execute the future result in a cascade order. When using a future chain the Eina_Value returned by a Eina_Future_Desc::cb will be delivered to the next Eina_Future_Desc::cb in the chain.
Here's an example:
Although it's possible to create a future chain using eina_future_then() and eina_future_then_from_desc() there's a function that makes this task much easier, please check eina_future_chain_array() for more information.
[in,out] | prev | A future to link against |
[in] | desc | A description struct containing the callback and data. |
NULL
on error. References EINA_SAFETY_ON_TRUE_GOTO.
EINA_API Eina_Future_Desc eina_future_cb_log_from_desc | ( | const Eina_Future_Cb_Log_Desc | desc | ) |
Creates an Eina_Future_Desc that will log the previous future resolved value.
This function can be used to quickly log the value that an Eina_Future_Desc::cb is returning. The returned value will be passed to the next future in the chain without modifications.
There are some helper macros like eina_future_cb_log_dbg() which will automatically fill the following fields:
__FILE__
function will be used. __func__
macro will be used. EINA_LOG_LEVEL_DBG
will be used. EINA_LOG_DOMAIN_DEFAULT
will be used. __LINE__
macro will be used.[in] | desc | The description data to be used. |
References _Eina_Future_Cb_Log_Desc::domain, EINA_SAFETY_ON_NULL_GOTO, _Eina_Future_Cb_Log_Desc::file, _Eina_Future_Cb_Log_Desc::func, _Eina_Future_Cb_Log_Desc::level, _Eina_Future_Cb_Log_Desc::line, _Eina_Future_Cb_Log_Desc::prefix, and _Eina_Future_Cb_Log_Desc::suffix.
EINA_API Eina_Future * eina_future_chain_array | ( | Eina_Future * | prev, |
const Eina_Future_Desc | descs[] | ||
) |
Creates a future chain.
This behaves exactly like eina_future_then_from_desc(), but makes it easier to create future chains.
If during the future chain creation an error happens this function will return NULL
, and the Eina_Future_Desc::cb from the descs
array will be called reporting an error (EINVAL
or ENOMEM
), so the user has a chance to free Eina_Future_Desc::data.
Just like eina_future_then_from_desc(), the value returned by a Eina_Future_Desc::cb callback will be delivered to the next Eina_Future_Desc::cb in the chain.
In case a future in the chain is canceled, the whole chain will be canceled immediately and the error ECANCELED
will be reported.
Here's an example:
[in,out] | prev | The previous future |
[in] | descs | An array of descriptions. The last element of the array must have the Eina_Future_Desc::cb set to NULL |
NULL
on error. References _Eina_Future_Desc::cb, EINA_SAFETY_ON_NULL_GOTO, and EINA_SAFETY_ON_TRUE_GOTO.
EINA_API Eina_Future * eina_future_chain_easy_array | ( | Eina_Future * | prev, |
const Eina_Future_Cb_Easy_Desc | descs[] | ||
) |
Wrapper around eina_future_chain_array() and eina_future_cb_easy_from_desc()
This functions makes it easier to use eina_future_chain_array() with eina_future_cb_easy_from_desc(), check the macro eina_future_chain_easy() for a syntax sugar.
[in,out] | prev | The previous future |
[in] | descs | An array of descriptions. The last element of the array must have the Eina_Future_Desc::cb set to NULL |
NULL
on error. References eina_future_cb_easy_from_desc(), EINA_SAFETY_ON_NULL_GOTO, EINA_SAFETY_ON_TRUE_GOTO, eina_value_flush(), _Eina_Future_Cb_Easy_Desc::error, _Eina_Future_Cb_Easy_Desc::free, _Eina_Future_Cb_Easy_Desc::success, and _Eina_Future_Cb_Easy_Desc::success_type.
EINA_API Eina_Future_Desc eina_future_cb_console_from_desc | ( | const Eina_Future_Cb_Console_Desc | desc | ) |
Creates an Eina_Future_Desc that will print the previous future's resolved value.
This function can be used to quickly inspect the value that an Eina_Future_Desc::cb is returning. The returned value will be passed to the next future in the chain without modifications.
There's also a helper macro called eina_future_cb_console() which makes this function easier to use.
Example:
[in] | desc | Description object with contextual information. |
The description object, desc
, can (optionally) include a prefix, suffix, filename and function name. If these are NULL
, empty strings ("") are used instead. If desc->suffix
is provided, the '\n' should be provided to ensure the printed string ends with a line feed.
References _Eina_Future_Desc::cb, _Eina_Future_Desc::data, EINA_SAFETY_ON_NULL_GOTO, _Eina_Future_Cb_Console_Desc::prefix, and _Eina_Future_Cb_Console_Desc::suffix.
EINA_API Eina_Future_Desc eina_future_cb_ignore_error | ( | Eina_Error | err | ) |
Returns an Eina_Future_Desc that ignores an error.
This function may be used if one wants to ignore an error. If the specified error happens an EINA_VALUE_EMPTY will be delivered to the next future in the chain.
[in] | err | The error to be ignored. |
EINA_API Eina_Future_Desc eina_future_cb_convert_to | ( | const Eina_Value_Type * | type | ) |
Creates an Eina_Future_Desc which will convert the received eina value to a given type.
[in] | type | The Eina_Value_Type to convert to. |
References _Eina_Future_Desc::cb.
EINA_API Eina_Future_Desc eina_future_cb_easy_from_desc | ( | const Eina_Future_Cb_Easy_Desc | desc | ) |
Creates an Eina_Future_Desc based on an Eina_Future_Cb_Easy_Desc.
This function aims to be used in conjunction with eina_future_chain(), eina_future_then_from_desc() and friends and its main objective is to simplify error handling and Eina_Value type checks. It uses three callbacks to inform the user about the future's result and life cycle. They are:
NULL
, this function will only be called if the future did not report an error. The value returned by this function will be propagated to the next future in the chain (if any).Check the example below for a sample usage:
[in] | desc | The easy callback's description. |
References EINA_SAFETY_ON_NULL_GOTO.
Referenced by eina_future_chain_easy_array().
EINA_API Eina_Promise * eina_promise_all_array | ( | Eina_Future * | array[] | ) |
Creates an all promise.
Creates a promise that is resolved once all the futures from the array
are resolved. The promise is resolved with an Eina_Value type array which contains EINA_VALUE_TYPE_VALUE elements. The result array is ordered according to the array
argument. Example:
[in,out] | array | An array of futures, terminated with EINA_FUTURE_SENTINEL. |
NULL
on error. References eina_mempool_free(), EINA_SAFETY_ON_FALSE_GOTO, EINA_SAFETY_ON_NULL_GOTO, EINA_SAFETY_ON_NULL_RETURN_VAL, eina_value_array_append(), eina_value_array_setup(), eina_value_flush(), eina_value_setup(), EINA_VALUE_TYPE_INT, and EINA_VALUE_TYPE_VALUE.
Referenced by eina_future_all_array().
EINA_API Eina_Promise * eina_promise_all_iterator | ( | Eina_Iterator * | iterator | ) |
Creates an all promise from an iterator.
Creates a promise that is resolved once all the futures from the iterator
are resolved. The promise is resolved with an Eina_Value type array which contains EINA_VALUE_TYPE_VALUE elements. The result array is ordered according to the iterator
order.
[in] | iterator | An iterator of futures. Will be destroyed after the call. |
NULL
on error. References eina_future_then, EINA_ITERATOR_FOREACH, eina_iterator_free(), eina_iterator_next(), eina_mempool_free(), eina_promise_new(), EINA_SAFETY_ON_FALSE_GOTO, EINA_SAFETY_ON_NULL_GOTO, EINA_SAFETY_ON_NULL_RETURN_VAL, eina_value_array_append(), eina_value_array_setup(), eina_value_flush(), eina_value_setup(), EINA_VALUE_TYPE_INT, and EINA_VALUE_TYPE_VALUE.
Referenced by eina_future_all_iterator().
EINA_API Eina_Promise * eina_promise_race_array | ( | Eina_Future * | array[] | ) |
Creates a race promise.
Creates a promise that resolves when a future from the array
is completed. The remaining futures will be canceled with the error code ECANCELED
The resulting value is an EINA_VALUE_TYPE_STRUCT with two fields:
value
containing an Eina_Value with the result itself. index
containing the index of the completed function relative to the array
.Example:
[in,out] | array | An array of futures, terminated by EINA_FUTURE_SENTINEL. |
NULL
on error. References EINA_SAFETY_ON_FALSE_GOTO, EINA_SAFETY_ON_NULL_GOTO, and EINA_SAFETY_ON_NULL_RETURN_VAL.
Referenced by eina_future_race_array().
|
inlinestatic |
Creates a future that will be resolved once all futures from array
is resolved.
This is a helper over eina_promise_all_array()
[in,out] | array | A future array, must be terminated with EINA_FUTURE_SENTINEL. |
References eina_future_new(), and eina_promise_all_array().
|
inlinestatic |
Creates a future that will be resolved once all futures from iterator
are resolved.
This is a helper over eina_promise_all_iterator()
[in] | iterator | An iterator containing futures. Will be destroyed on exit of the function. |
References eina_future_new(), and eina_promise_all_iterator().
|
inlinestatic |
Creates a future that will be resolved once a future array
is resolved.
This is a helper over eina_promise_race_array()
[in,out] | array | A future array, must be terminated with EINA_FUTURE_SENTINEL |
References eina_future_new(), and eina_promise_race_array().
|
extern |
A pointer to the race struct description, which is used by eina_promise_race_array().
This struct contains two members:
value:
An EINA_VALUE_TYPE_VALUE that contains the future result that won the race. index:
An EINA_VALUE_TYPE_UINT that contains the future index that won the race.