summaryrefslogtreecommitdiff
path: root/src/examples/ecore/ecore_promise2_example.c
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2019-01-04 17:42:26 -0800
committerCedric BAIL <cedric.bail@free.fr>2019-01-16 14:33:26 -0800
commit563f91eaf98fff474a4858f2d81c6374f0d777b9 (patch)
tree2e3a8abf52d835da7a74d1285ae45a17410cd763 /src/examples/ecore/ecore_promise2_example.c
parent40ca3fbe5813dfe0f2d0090f421c22a4cf2d8817 (diff)
ecore: remove data parameters of Efl.Loop_Consumer.promise_new to reduce the risk of inadvertently using the wrong data.
If you need data, use a efl_future_then as done in every case here to get the same feature. Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Differential Revision: https://phab.enlightenment.org/D7577
Diffstat (limited to '')
-rw-r--r--src/examples/ecore/ecore_promise2_example.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/examples/ecore/ecore_promise2_example.c b/src/examples/ecore/ecore_promise2_example.c
index d10acf0450..7ddb426b1a 100644
--- a/src/examples/ecore/ecore_promise2_example.c
+++ b/src/examples/ecore/ecore_promise2_example.c
@@ -43,11 +43,13 @@ _timeout(void *data, const Eina_Value v, const Eina_Future *dead_future EINA_UNU
43 return v; 43 return v;
44} 44}
45 45
46static void 46static Eina_Value
47_promise_cancel(void *data, const Eina_Promise *dead EINA_UNUSED) 47_promise_cancel(Eo *o EINA_UNUSED, void *data, Eina_Error error)
48{ 48{
49 Ctx *ctx = data; 49 Ctx *ctx = data;
50 if (ctx->timer) eina_future_cancel(ctx->timer); 50
51 if (error == ECANCELED && ctx->timer) eina_future_cancel(ctx->timer);
52 return eina_value_error_init(error);
51} 53}
52 54
53static Ctx * 55static Ctx *
@@ -56,7 +58,7 @@ _promise_ctx_new(Efl_Loop *loop, Eina_Value *v)
56 Ctx *ctx; 58 Ctx *ctx;
57 ctx = calloc(1, sizeof(Ctx)); 59 ctx = calloc(1, sizeof(Ctx));
58 EINA_SAFETY_ON_NULL_GOTO(ctx, err_ctx); 60 EINA_SAFETY_ON_NULL_GOTO(ctx, err_ctx);
59 ctx->p = efl_loop_promise_new(loop, ctx, _promise_cancel, NULL); 61 ctx->p = efl_loop_promise_new(loop, NULL);
60 EINA_SAFETY_ON_NULL_GOTO(ctx->p, err_timer); 62 EINA_SAFETY_ON_NULL_GOTO(ctx->p, err_timer);
61 ctx->value = v; 63 ctx->value = v;
62 return ctx; 64 return ctx;
@@ -76,7 +78,7 @@ _future_get(Ctx *ctx, Efl_Loop *loop)
76 EINA_SAFETY_ON_NULL_GOTO(f, err_future); 78 EINA_SAFETY_ON_NULL_GOTO(f, err_future);
77 ctx->timer = eina_future_then(efl_loop_timeout(loop, 0.1), _timeout, ctx); 79 ctx->timer = eina_future_then(efl_loop_timeout(loop, 0.1), _timeout, ctx);
78 EINA_SAFETY_ON_NULL_GOTO(ctx->timer, err_timer); 80 EINA_SAFETY_ON_NULL_GOTO(ctx->timer, err_timer);
79 return f; 81 return efl_future_then(loop, f, .error = _promise_cancel, .data = ctx);
80 82
81 err_timer: 83 err_timer:
82 eina_future_cancel(f); 84 eina_future_cancel(f);