Commit bc6c8809 authored by Debarshi Ray's avatar Debarshi Ray Committed by Christian Hergert

egg-task-cache: Set up and invoke the in-flight GTask in two steps

Proper cancellation handling, when multiple tasks are queued for a
given key, requires that the caller's GCancellable::cancelled be
monitored. Fetching of the value should be aborted once all the queued
tasks have been cancelled.

It will be nice to cancel the in-flight GTask even before it's invoked,
if the first caller's GCancellable is already cancelled.

Therefore, it will simplify the GCancellable::cancelled handler if the
connection to it is made after the in-flight GTask has been created
and added to the GHashTable, but before it has been invoked. This is
meant to help with that.

https://bugzilla.gnome.org/show_bug.cgi?id=779660
parent 4ef15fc8
......@@ -466,6 +466,7 @@ egg_task_cache_get_async (EggTaskCache *self,
GAsyncReadyCallback callback,
gpointer user_data)
{
g_autoptr(GTask) fetch_task = NULL;
g_autoptr(GTask) task = NULL;
GPtrArray *queued;
gpointer ret;
......@@ -510,8 +511,6 @@ egg_task_cache_get_async (EggTaskCache *self,
*/
if (!g_hash_table_contains (self->in_flight, key))
{
g_autoptr(GTask) fetch_task = NULL;
fetch_task = g_task_new (self,
cancellable,
egg_task_cache_fetch_cb,
......@@ -519,6 +518,10 @@ egg_task_cache_get_async (EggTaskCache *self,
g_hash_table_insert (self->in_flight,
self->key_copy_func ((gpointer)key),
g_object_ref (fetch_task));
}
if (fetch_task != NULL)
{
self->populate_callback (self,
key,
g_object_ref (fetch_task),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment