summaryrefslogtreecommitdiff
path: root/src/lib/eina/eina_promise.c
diff options
context:
space:
mode:
authorFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-05-25 18:14:29 -0300
committerFelipe Magno de Almeida <felipe@expertisesolutions.com.br>2016-05-25 21:32:03 -0300
commitde9be13d458f2739a536e5863aa8caddd3f7f715 (patch)
tree7e28d9dba5336f02ad148af679e7208377fae9f0 /src/lib/eina/eina_promise.c
parent0eacdc03da738bebe03ac22fe377836751877345 (diff)
eina: Add promise parameter to then calllbacks
Added promise parameter to then callbacks so callbacks can steal ownership of the value from the promise.
Diffstat (limited to '')
-rw-r--r--src/lib/eina/eina_promise.c30
1 files changed, 26 insertions, 4 deletions
diff --git a/src/lib/eina/eina_promise.c b/src/lib/eina/eina_promise.c
index 93e70948e5..e8ef06d781 100644
--- a/src/lib/eina/eina_promise.c
+++ b/src/lib/eina/eina_promise.c
@@ -169,11 +169,11 @@ _eina_promise_then_calls(_Eina_Promise_Default_Owner* promise)
169 if (error) 169 if (error)
170 { 170 {
171 if (callback->error_cb) 171 if (callback->error_cb)
172 (*callback->error_cb)(callback->data, &promise->promise.error); 172 (*callback->error_cb)(callback->data, promise->promise.error, &promise->promise.vtable);
173 } 173 }
174 else if (callback->callback) 174 else if (callback->callback)
175 { 175 {
176 (*callback->callback)(callback->data, &promise->value[0]); 176 (*callback->callback)(callback->data, &promise->value[0], &promise->promise.vtable);
177 } 177 }
178 free(callback); 178 free(callback);
179 _eina_promise_unref(&promise->promise); 179 _eina_promise_unref(&promise->promise);
@@ -240,8 +240,23 @@ _eina_promise_value_get(_Eina_Promise_Default const* p)
240 } 240 }
241} 241}
242 242
243static void *
244_eina_promise_release_value_ownership(_Eina_Promise_Default* p)
245{
246 _Eina_Promise_Default_Owner* promise = EINA_PROMISE_GET_OWNER(p);
247 if (promise->promise.has_finished && !promise->promise.has_errored)
248 {
249 promise->promise.value_free_cb = NULL;
250 return (void*)&promise->value[0];
251 }
252 else
253 {
254 return NULL;
255 }
256}
257
243static void 258static void
244_eina_promise_owner_value_set(_Eina_Promise_Default_Owner* promise, void* data, Eina_Promise_Free_Cb free) 259_eina_promise_owner_value_set(_Eina_Promise_Default_Owner* promise, const void* data, Eina_Promise_Free_Cb free)
245{ 260{
246 if (data && promise->promise.value_size) 261 if (data && promise->promise.value_size)
247 { 262 {
@@ -481,6 +496,7 @@ eina_promise_default_add(int value_size)
481 p->promise.vtable.ref = EINA_FUNC_PROMISE_REF(_eina_promise_ref); 496 p->promise.vtable.ref = EINA_FUNC_PROMISE_REF(_eina_promise_ref);
482 p->promise.vtable.unref = EINA_FUNC_PROMISE_UNREF(_eina_promise_unref); 497 p->promise.vtable.unref = EINA_FUNC_PROMISE_UNREF(_eina_promise_unref);
483 p->promise.vtable.value_size_get = EINA_FUNC_PROMISE_VALUE_SIZE_GET(_eina_promise_value_size_get); 498 p->promise.vtable.value_size_get = EINA_FUNC_PROMISE_VALUE_SIZE_GET(_eina_promise_value_size_get);
499 p->promise.vtable.release_value_ownership = EINA_FUNC_PROMISE_RELEASE_VALUE_OWNERSHIP(_eina_promise_release_value_ownership);
484 p->promise.has_finished = p->promise.has_errored = 500 p->promise.has_finished = p->promise.has_errored =
485 p->promise.is_cancelled = p->promise.is_manual_then = EINA_FALSE; 501 p->promise.is_cancelled = p->promise.is_manual_then = EINA_FALSE;
486 p->promise.is_first_then = EINA_TRUE; 502 p->promise.is_first_then = EINA_TRUE;
@@ -781,7 +797,7 @@ eina_promise_then(Eina_Promise* promise, Eina_Promise_Cb callback,
781} 797}
782 798
783EAPI void 799EAPI void
784eina_promise_owner_value_set(Eina_Promise_Owner* promise, void* value, Eina_Promise_Free_Cb free) 800eina_promise_owner_value_set(Eina_Promise_Owner* promise, const void* value, Eina_Promise_Free_Cb free)
785{ 801{
786 promise->value_set(promise, value, free); 802 promise->value_set(promise, value, free);
787} 803}
@@ -847,6 +863,12 @@ eina_promise_buffer_get(Eina_Promise* promise)
847 return promise->buffer_get(promise); 863 return promise->buffer_get(promise);
848} 864}
849 865
866EAPI void *
867eina_promise_release_value_ownership(Eina_Promise* promise)
868{
869 return promise->release_value_ownership(promise);
870}
871
850EAPI size_t 872EAPI size_t
851eina_promise_value_size_get(Eina_Promise const* promise) 873eina_promise_value_size_get(Eina_Promise const* promise)
852{ 874{