forked from enlightenment/efl
ecore: promise for timeout and job are clearly never optional, so return them.
This commit is contained in:
parent
7344417306
commit
4f43c27450
|
@ -2872,20 +2872,31 @@ _efl_internal_promise_new(Eina_Promise_Owner* promise, const void *data)
|
|||
return p;
|
||||
}
|
||||
|
||||
static void
|
||||
_efl_loop_job(Eo *obj EINA_UNUSED, Efl_Loop_Data *pd EINA_UNUSED, Eina_Promise_Owner *promise, const void *data)
|
||||
static Eina_Promise *
|
||||
_efl_loop_job(Eo *obj EINA_UNUSED, Efl_Loop_Data *pd EINA_UNUSED, const void *data)
|
||||
{
|
||||
Efl_Internal_Promise *j;
|
||||
Eina_Promise_Owner *promise;
|
||||
|
||||
promise = eina_promise_default_add(sizeof (void*));
|
||||
fprintf(stderr, "da promise: %p\n", promise);
|
||||
if (!promise) return NULL;
|
||||
|
||||
j = _efl_internal_promise_new(promise, data);
|
||||
if (!j) return ;
|
||||
fprintf(stderr, "da internal job: %p\n", j);
|
||||
if (!j) goto on_error;
|
||||
|
||||
j->job_is = EINA_TRUE;
|
||||
j->u.job = ecore_job_add(_efl_loop_job_cb, j);
|
||||
if (!j->u.job) goto on_error;
|
||||
|
||||
if (j->u.job) return ;
|
||||
return eina_promise_owner_promise_get(promise);
|
||||
|
||||
_efl_loop_internal_cancel(j);
|
||||
on_error:
|
||||
eina_promise_unref(eina_promise_owner_promise_get(promise));
|
||||
free(j);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* This event will be triggered when the main loop is destroyed and destroy its timers along */
|
||||
|
@ -2901,22 +2912,32 @@ EO_CALLBACKS_ARRAY_DEFINE(timeout,
|
|||
{ EFL_TIMER_EVENT_TICK, _efl_loop_timeout_cb },
|
||||
{ EO_EVENT_DEL, _efl_loop_timeout_force_cancel_cb });
|
||||
|
||||
static void
|
||||
_efl_loop_timeout(Eo *obj, Efl_Loop_Data *pd EINA_UNUSED, Eina_Promise_Owner *promise, double time, const void *data)
|
||||
static Eina_Promise *
|
||||
_efl_loop_timeout(Eo *obj, Efl_Loop_Data *pd EINA_UNUSED, double time, const void *data)
|
||||
{
|
||||
Efl_Internal_Promise *t;
|
||||
Eina_Promise_Owner *promise;
|
||||
|
||||
promise = eina_promise_default_add(sizeof (void*));
|
||||
if (!promise) return NULL;
|
||||
|
||||
t = _efl_internal_promise_new(promise, data);
|
||||
if (!t) return ;
|
||||
if (!t) goto on_error;
|
||||
|
||||
t->job_is = EINA_FALSE;
|
||||
t->u.timer = eo_add(EFL_TIMER_CLASS, obj,
|
||||
efl_timer_interval_set(eo_self, time),
|
||||
eo_event_callback_array_add(eo_self, timeout(), t));
|
||||
|
||||
if (t->u.timer) return ;
|
||||
if (!t->u.timer) goto on_error;
|
||||
|
||||
_efl_loop_internal_cancel(t);
|
||||
return eina_promise_owner_promise_get(promise);
|
||||
|
||||
on_error:
|
||||
eina_promise_unref(eina_promise_owner_promise_get(promise));
|
||||
free(t);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#include "efl_loop.eo.c"
|
||||
|
|
|
@ -33,17 +33,18 @@ class Efl.Loop (Eo.Base)
|
|||
job {
|
||||
[[Will execute that promise in the near future.]]
|
||||
params {
|
||||
@inout promise: promise<void*>*; [[The promise that will be triggered.]]
|
||||
@in data: const(void)* @optional; [[The data to be given when the promise is done.]]
|
||||
}
|
||||
return: promise<void*>*; [[The promise that will be triggered.]]
|
||||
}
|
||||
timeout {
|
||||
[[Will trigger this promise when the specified timeout occur.]]
|
||||
params {
|
||||
@inout promise: promise<void*>*; [[The promise that will be triggered.]]
|
||||
@in time: double; [[The time from now in second that the main loop will wait before triggering it.]]
|
||||
@in data: const(void)* @optional; [[The data to be given when the promise is done.]]
|
||||
}
|
||||
return: promise<void*>*; [[The promise that will be triggered.]]
|
||||
|
||||
}
|
||||
}
|
||||
events {
|
||||
|
|
|
@ -22,7 +22,7 @@ START_TEST(ecore_test_job_promise)
|
|||
|
||||
ecore_init();
|
||||
|
||||
efl_loop_job(ecore_main_loop_get(), &job, &bob);
|
||||
job = efl_loop_job(ecore_main_loop_get(), &bob);
|
||||
eina_promise_then(job, &_ecore_promise_quit, NULL, &bob);
|
||||
|
||||
ecore_main_loop_begin();
|
||||
|
|
|
@ -197,7 +197,7 @@ START_TEST(ecore_test_timeout)
|
|||
ecore_init();
|
||||
|
||||
start = ecore_time_get();
|
||||
efl_loop_timeout(ecore_main_loop_get(), &timeout, 0.2, &start);
|
||||
timeout = efl_loop_timeout(ecore_main_loop_get(), 0.2, &start);
|
||||
eina_promise_then(timeout, &_ecore_promise_quit, NULL, &bob);
|
||||
|
||||
ecore_main_loop_begin();
|
||||
|
|
Loading…
Reference in New Issue