Task

A gio.task.Task represents and manages a cancellable ‘task’.

Asynchronous operations

The most common usage of gio.task.Task is as a gio.async_result.AsyncResult, to manage data during an asynchronous operation. You call gio.task.Task.new_ in the ‘start’ method, followed by gio.task.Task.setTaskData and the like if you need to keep some additional data associated with the task, and then pass the task object around through your asynchronous operation. Eventually, you will call a method such as gio.task.Task.returnPointer or gio.task.Task.returnError, which will save the value you give it and then invoke the task’s callback function in the thread-default main context (see glib.main_context.MainContext.pushThreadDefault) where it was created (waiting until the next iteration of the main loop first, if necessary). The caller will pass the gio.task.Task back to the operation’s finish function (as a gio.async_result.AsyncResult), and you can use gio.task.Task.propagatePointer or the like to extract the return value.

Using gio.task.Task requires the thread-default glib.main_context.MainContext from when the gio.task.Task was constructed to be running at least until the task has completed and its data has been freed.

If a gio.task.Task has been constructed and its callback set, it is an error to not call g_task_return_*() on it. GLib will warn at runtime if this happens (since 2.76).

Here is an example for using gio.task.Task as a gio.async_result.AsyncResult:

1 typedef struct {
2   CakeFrostingType frosting;
3   char *message;
4 } DecorationData;
5 
6 static void
7 decoration_data_free (DecorationData *decoration)
8 {
9   g_free (decoration->message);
10   g_slice_free (DecorationData, decoration);
11 }
12 
13 static void
14 baked_cb (Cake     *cake,
15           gpointer  user_data)
16 {
17   GTask *task = user_data;
18   DecorationData *decoration = g_task_get_task_data (task);
19   GError *error = NULL;
20 
21   if (cake == NULL)
22     {
23       g_task_return_new_error (task, BAKER_ERROR, BAKER_ERROR_NO_FLOUR,
24                                "Go to the supermarket");
25       g_object_unref (task);
26       return;
27     }
28 
29   if (!cake_decorate (cake, decoration->frosting, decoration->message, &error))
30     {
31       g_object_unref (cake);
32       // g_task_return_error() takes ownership of error
33       g_task_return_error (task, error);
34       g_object_unref (task);
35       return;
36     }
37 
38   g_task_return_pointer (task, cake, g_object_unref);
39   g_object_unref (task);
40 }
41 
42 void
43 baker_bake_cake_async (Baker               *self,
44                        guint                radius,
45                        CakeFlavor           flavor,
46                        CakeFrostingType     frosting,
47                        const char          *message,
48                        GCancellable        *cancellable,
49                        GAsyncReadyCallback  callback,
50                        gpointer             user_data)
51 {
52   GTask *task;
53   DecorationData *decoration;
54   Cake  *cake;
55 
56   task = g_task_new (self, cancellable, callback, user_data);
57   if (radius < 3)
58     {
59       g_task_return_new_error (task, BAKER_ERROR, BAKER_ERROR_TOO_SMALL,
60                                "%ucm radius cakes are silly",
61                                radius);
62       g_object_unref (task);
63       return;
64     }
65 
66   cake = _baker_get_cached_cake (self, radius, flavor, frosting, message);
67   if (cake != NULL)
68     {
69       // _baker_get_cached_cake() returns a reffed cake
70       g_task_return_pointer (task, cake, g_object_unref);
71       g_object_unref (task);
72       return;
73     }
74 
75   decoration = g_slice_new (DecorationData);
76   decoration->frosting = frosting;
77   decoration->message = g_strdup (message);
78   g_task_set_task_data (task, decoration, (GDestroyNotify) decoration_data_free);
79 
80   _baker_begin_cake (self, radius, flavor, cancellable, baked_cb, task);
81 }
82 
83 Cake *
84 baker_bake_cake_finish (Baker         *self,
85                         GAsyncResult  *result,
86                         GError       **error)
87 {
88   g_return_val_if_fail (g_task_is_valid (result, self), NULL);
89 
90   return g_task_propagate_pointer (G_TASK (result), error);
91 }

Chained asynchronous operations

gio.task.Task also tries to simplify asynchronous operations that internally chain together several smaller asynchronous operations. gio.task.Task.getCancellable, gio.task.Task.getContext, and gio.task.Task.getPriority allow you to get back the task’s gio.cancellable.Cancellable, glib.main_context.MainContext, and I/O priority

when starting a new subtask, so you don’t have to keep track of them yourself. gio.task.Task.attachSource simplifies the case of waiting for a source to fire (automatically using the correct glib.main_context.MainContext and priority).

Here is an example for chained asynchronous operations:

1 typedef struct {
2   Cake *cake;
3   CakeFrostingType frosting;
4   char *message;
5 } BakingData;
6 
7 static void
8 decoration_data_free (BakingData *bd)
9 {
10   if (bd->cake)
11     g_object_unref (bd->cake);
12   g_free (bd->message);
13   g_slice_free (BakingData, bd);
14 }
15 
16 static void
17 decorated_cb (Cake         *cake,
18               GAsyncResult *result,
19               gpointer      user_data)
20 {
21   GTask *task = user_data;
22   GError *error = NULL;
23 
24   if (!cake_decorate_finish (cake, result, &error))
25     {
26       g_object_unref (cake);
27       g_task_return_error (task, error);
28       g_object_unref (task);
29       return;
30     }
31 
32   // baking_data_free() will drop its ref on the cake, so we have to
33   // take another here to give to the caller.
34   g_task_return_pointer (task, g_object_ref (cake), g_object_unref);
35   g_object_unref (task);
36 }
37 
38 static gboolean
39 decorator_ready (gpointer user_data)
40 {
41   GTask *task = user_data;
42   BakingData *bd = g_task_get_task_data (task);
43 
44   cake_decorate_async (bd->cake, bd->frosting, bd->message,
45                        g_task_get_cancellable (task),
46                        decorated_cb, task);
47 
48   return G_SOURCE_REMOVE;
49 }
50 
51 static void
52 baked_cb (Cake     *cake,
53           gpointer  user_data)
54 {
55   GTask *task = user_data;
56   BakingData *bd = g_task_get_task_data (task);
57   GError *error = NULL;
58 
59   if (cake == NULL)
60     {
61       g_task_return_new_error (task, BAKER_ERROR, BAKER_ERROR_NO_FLOUR,
62                                "Go to the supermarket");
63       g_object_unref (task);
64       return;
65     }
66 
67   bd->cake = cake;
68 
69   // Bail out now if the user has already cancelled
70   if (g_task_return_error_if_cancelled (task))
71     {
72       g_object_unref (task);
73       return;
74     }
75 
76   if (cake_decorator_available (cake))
77     decorator_ready (task);
78   else
79     {
80       GSource *source;
81 
82       source = cake_decorator_wait_source_new (cake);
83       // Attach @source to @task’s GMainContext and have it call
84       // decorator_ready() when it is ready.
85       g_task_attach_source (task, source, decorator_ready);
86       g_source_unref (source);
87     }
88 }
89 
90 void
91 baker_bake_cake_async (Baker               *self,
92                        guint                radius,
93                        CakeFlavor           flavor,
94                        CakeFrostingType     frosting,
95                        const char          *message,
96                        gint                 priority,
97                        GCancellable        *cancellable,
98                        GAsyncReadyCallback  callback,
99                        gpointer             user_data)
100 {
101   GTask *task;
102   BakingData *bd;
103 
104   task = g_task_new (self, cancellable, callback, user_data);
105   g_task_set_priority (task, priority);
106 
107   bd = g_slice_new0 (BakingData);
108   bd->frosting = frosting;
109   bd->message = g_strdup (message);
110   g_task_set_task_data (task, bd, (GDestroyNotify) baking_data_free);
111 
112   _baker_begin_cake (self, radius, flavor, cancellable, baked_cb, task);
113 }
114 
115 Cake *
116 baker_bake_cake_finish (Baker         *self,
117                         GAsyncResult  *result,
118                         GError       **error)
119 {
120   g_return_val_if_fail (g_task_is_valid (result, self), NULL);
121 
122   return g_task_propagate_pointer (G_TASK (result), error);
123 }

Asynchronous operations from synchronous ones

You can use gio.task.Task.runInThread to turn a synchronous operation into an asynchronous one, by running it in a thread. When it completes, the result will be dispatched to the thread-default main context (see glib.main_context.MainContext.pushThreadDefault) where the gio.task.Task was created.

Running a task in a thread:

1 typedef struct {
2   guint radius;
3   CakeFlavor flavor;
4   CakeFrostingType frosting;
5   char *message;
6 } CakeData;
7 
8 static void
9 cake_data_free (CakeData *cake_data)
10 {
11   g_free (cake_data->message);
12   g_slice_free (CakeData, cake_data);
13 }
14 
15 static void
16 bake_cake_thread (GTask         *task,
17                   gpointer       source_object,
18                   gpointer       task_data,
19                   GCancellable  *cancellable)
20 {
21   Baker *self = source_object;
22   CakeData *cake_data = task_data;
23   Cake *cake;
24   GError *error = NULL;
25 
26   cake = bake_cake (baker, cake_data->radius, cake_data->flavor,
27                     cake_data->frosting, cake_data->message,
28                     cancellable, &error);
29   if (cake)
30     g_task_return_pointer (task, cake, g_object_unref);
31   else
32     g_task_return_error (task, error);
33 }
34 
35 void
36 baker_bake_cake_async (Baker               *self,
37                        guint                radius,
38                        CakeFlavor           flavor,
39                        CakeFrostingType     frosting,
40                        const char          *message,
41                        GCancellable        *cancellable,
42                        GAsyncReadyCallback  callback,
43                        gpointer             user_data)
44 {
45   CakeData *cake_data;
46   GTask *task;
47 
48   cake_data = g_slice_new (CakeData);
49   cake_data->radius = radius;
50   cake_data->flavor = flavor;
51   cake_data->frosting = frosting;
52   cake_data->message = g_strdup (message);
53   task = g_task_new (self, cancellable, callback, user_data);
54   g_task_set_task_data (task, cake_data, (GDestroyNotify) cake_data_free);
55   g_task_run_in_thread (task, bake_cake_thread);
56   g_object_unref (task);
57 }
58 
59 Cake *
60 baker_bake_cake_finish (Baker         *self,
61                         GAsyncResult  *result,
62                         GError       **error)
63 {
64   g_return_val_if_fail (g_task_is_valid (result, self), NULL);
65 
66   return g_task_propagate_pointer (G_TASK (result), error);
67 }

Adding cancellability to uncancellable tasks

Finally, gio.task.Task.runInThread and gio.task.Task.runInThreadSync can be used to turn an uncancellable operation into a cancellable one. If you call gio.task.Task.setReturnOnCancel, passing TRUE, then if the task’s gio.cancellable.Cancellable is cancelled, it will return control back to the caller immediately, while allowing the task thread to continue running in the background (and simply discarding its result when it finally does finish). Provided that the task thread is careful about how it uses locks and other externally-visible resources, this allows you to make ‘GLib-friendly’ asynchronous and cancellable synchronous variants of blocking APIs.

Cancelling a task:

1 static void
2 bake_cake_thread (GTask         *task,
3                   gpointer       source_object,
4                   gpointer       task_data,
5                   GCancellable  *cancellable)
6 {
7   Baker *self = source_object;
8   CakeData *cake_data = task_data;
9   Cake *cake;
10   GError *error = NULL;
11 
12   cake = bake_cake (baker, cake_data->radius, cake_data->flavor,
13                     cake_data->frosting, cake_data->message,
14                     &error);
15   if (error)
16     {
17       g_task_return_error (task, error);
18       return;
19     }
20 
21   // If the task has already been cancelled, then we don’t want to add
22   // the cake to the cake cache. Likewise, we don’t  want to have the
23   // task get cancelled in the middle of updating the cache.
24   // g_task_set_return_on_cancel() will return %TRUE here if it managed
25   // to disable return-on-cancel, or %FALSE if the task was cancelled
26   // before it could.
27   if (g_task_set_return_on_cancel (task, FALSE))
28     {
29       // If the caller cancels at this point, their
30       // GAsyncReadyCallback won’t be invoked until we return,
31       // so we don’t have to worry that this code will run at
32       // the same time as that code does. But if there were
33       // other functions that might look at the cake cache,
34       // then we’d probably need a GMutex here as well.
35       baker_add_cake_to_cache (baker, cake);
36       g_task_return_pointer (task, cake, g_object_unref);
37     }
38 }
39 
40 void
41 baker_bake_cake_async (Baker               *self,
42                        guint                radius,
43                        CakeFlavor           flavor,
44                        CakeFrostingType     frosting,
45                        const char          *message,
46                        GCancellable        *cancellable,
47                        GAsyncReadyCallback  callback,
48                        gpointer             user_data)
49 {
50   CakeData *cake_data;
51   GTask *task;
52 
53   cake_data = g_slice_new (CakeData);
54 
55   ...
56 
57   task = g_task_new (self, cancellable, callback, user_data);
58   g_task_set_task_data (task, cake_data, (GDestroyNotify) cake_data_free);
59   g_task_set_return_on_cancel (task, TRUE);
60   g_task_run_in_thread (task, bake_cake_thread);
61 }
62 
63 Cake *
64 baker_bake_cake_sync (Baker               *self,
65                       guint                radius,
66                       CakeFlavor           flavor,
67                       CakeFrostingType     frosting,
68                       const char          *message,
69                       GCancellable        *cancellable,
70                       GError             **error)
71 {
72   CakeData *cake_data;
73   GTask *task;
74   Cake *cake;
75 
76   cake_data = g_slice_new (CakeData);
77 
78   ...
79 
80   task = g_task_new (self, cancellable, NULL, NULL);
81   g_task_set_task_data (task, cake_data, (GDestroyNotify) cake_data_free);
82   g_task_set_return_on_cancel (task, TRUE);
83   g_task_run_in_thread_sync (task, bake_cake_thread);
84 
85   cake = g_task_propagate_pointer (task, error);
86   g_object_unref (task);
87   return cake;
88 }

Porting from gio.simple_async_result.SimpleAsyncResult

gio.task.Task’s API attempts to be simpler than gio.simple_async_result.SimpleAsyncResult’s in several ways:

Thread-safety considerations

Due to some infelicities in the API design, there is a thread-safety concern that users of gio.task.Task have to be aware of:

If the main thread drops its last reference to the source object or the task data before the task is finalized, then the finalizers of these objects may be called on the worker thread.

This is a problem if the finalizers use non-threadsafe API, and can lead to hard-to-debug crashes. Possible workarounds include:

  • Clear task data in a signal handler for notify::completed
  • Keep iterating a main context in the main thread and defer dropping the reference to the source object to that main context when the task is finalized
class Task : ObjectG , AsyncResult {}

Constructors

this
this(gobject.object.ObjectG sourceObject, gio.cancellable.Cancellable cancellable, gio.types.AsyncReadyCallback callback)

Creates a #GTask acting on source_object, which will eventually be used to invoke callback in the current [thread-default main context][g-main-context-push-thread-default].

Members

Functions

getCancellable
gio.cancellable.Cancellable getCancellable()

Gets task's #GCancellable

getCheckCancellable
bool getCheckCancellable()

Gets task's check-cancellable flag. See gio.task.Task.setCheckCancellable for more details.

getCompleted
bool getCompleted()

Gets the value of #GTask:completed. This changes from false to true after the task’s callback is invoked, and will return false if called from inside the callback.

getContext
glib.main_context.MainContext getContext()

Gets the #GMainContext that task will return its result in (that is, the context that was the [thread-default main context][g-main-context-push-thread-default] at the point when task was created).

getName
string getName()

Gets task’s name. See gio.task.Task.setName.

getPriority
int getPriority()

Gets task's priority

getReturnOnCancel
bool getReturnOnCancel()

Gets task's return-on-cancel flag. See gio.task.Task.setReturnOnCancel for more details.

getSourceObject
gobject.object.ObjectG getSourceObject()

Gets the source object from task. Like gio.async_result.AsyncResult.getSourceObject, but does not ref the object.

getSourceTag
void* getSourceTag()

Gets task's source tag. See gio.task.Task.setSourceTag.

getTaskData
void* getTaskData()

Gets task's task_data.

hadError
bool hadError()

Tests if task resulted in an error.

propagateBoolean
bool propagateBoolean()

Gets the result of task as a #gboolean.

propagateInt
ptrdiff_t propagateInt()

Gets the result of task as an integer (#gssize).

propagatePointer
void* propagatePointer()

Gets the result of task as a pointer, and transfers ownership of that value to the caller.

propagateValue
bool propagateValue(gobject.value.Value value)

Gets the result of task as a #GValue, and transfers ownership of that value to the caller. As with gio.task.Task.returnValue, this is a generic low-level method; gio.task.Task.propagatePointer and the like will usually be more useful for C code.

returnBoolean
void returnBoolean(bool result)

Sets task's result to result and completes the task (see gio.task.Task.returnPointer for more discussion of exactly what this means).

returnError
void returnError(glib.error.ErrorG error)

Sets task's result to error (which task assumes ownership of) and completes the task (see gio.task.Task.returnPointer for more discussion of exactly what this means).

returnErrorIfCancelled
bool returnErrorIfCancelled()

Checks if task's #GCancellable has been cancelled, and if so, sets task's error accordingly and completes the task (see gio.task.Task.returnPointer for more discussion of exactly what this means).

returnInt
void returnInt(ptrdiff_t result)

Sets task's result to result and completes the task (see gio.task.Task.returnPointer for more discussion of exactly what this means).

returnNewErrorLiteral
void returnNewErrorLiteral(glib.types.Quark domain, int code, string message)

Sets task’s result to a new glib.error.ErrorG created from domain, code, message and completes the task.

returnPointer
void returnPointer(void* result, glib.types.DestroyNotify resultDestroy)

Sets task's result to result and completes the task. If result is not null, then result_destroy will be used to free result if the caller does not take ownership of it with gio.task.Task.propagatePointer.

returnValue
void returnValue(gobject.value.Value result)

Sets task's result to result (by copying it) and completes the task.

runInThread
void runInThread(gio.types.TaskThreadFunc taskFunc)

Runs task_func in another thread. When task_func returns, task's #GAsyncReadyCallback will be invoked in task's #GMainContext.

runInThreadSync
void runInThreadSync(gio.types.TaskThreadFunc taskFunc)

Runs task_func in another thread, and waits for it to return or be cancelled. You can use gio.task.Task.propagatePointer, etc, afterward to get the result of task_func.

setCheckCancellable
void setCheckCancellable(bool checkCancellable)

Sets or clears task's check-cancellable flag. If this is true (the default), then gio.task.Task.propagatePointer, etc, and gio.task.Task.hadError will check the task's #GCancellable first, and if it has been cancelled, then they will consider the task to have returned an "Operation was cancelled" error (gio.types.IOErrorEnum.Cancelled), regardless of any other error or return value the task may have had.

setName
void setName(string name)

Sets task’s name, used in debugging and profiling. The name defaults to null.

setPriority
void setPriority(int priority)

Sets task's priority. If you do not call this, it will default to G_PRIORITY_DEFAULT.

setReturnOnCancel
bool setReturnOnCancel(bool returnOnCancel)

Sets or clears task's return-on-cancel flag. This is only meaningful for tasks run via gio.task.Task.runInThread or gio.task.Task.runInThreadSync.

setSourceTag
void setSourceTag(void* sourceTag)

Sets task's source tag.

setStaticName
void setStaticName(string name)

Sets task’s name, used in debugging and profiling.

setTaskData
void setTaskData(void* taskData, glib.types.DestroyNotify taskDataDestroy)

Sets task's task data (freeing the existing task data, if any).

Static functions

isValid
bool isValid(gio.async_result.AsyncResult result, gobject.object.ObjectG sourceObject)

Checks that result is a #GTask, and that source_object is its source object (or that source_object is null and result has no source object). This can be used in g_return_if_fail() checks.

reportError
void reportError(gobject.object.ObjectG sourceObject, gio.types.AsyncReadyCallback callback, void* sourceTag, glib.error.ErrorG error)

Creates a #GTask and then immediately calls gio.task.Task.returnError on it. Use this in the wrapper function of an asynchronous method when you want to avoid even calling the virtual method. You can then use gio.async_result.AsyncResult.isTagged in the finish method wrapper to check if the result there is tagged as having been created by the wrapper method, and deal with it appropriately if so.

Mixed In Members

From mixin AsyncResultT!()

getSourceObject
gobject.object.ObjectG getSourceObject()

Gets the source object from a #GAsyncResult.

getUserData
void* getUserData()

Gets the user data from a #GAsyncResult.

isTagged
bool isTagged(void* sourceTag)

Checks if res has the given source_tag (generally a function pointer indicating the function res was created by).

legacyPropagateError
bool legacyPropagateError()

If res is a #GSimpleAsyncResult, this is equivalent to gio.simple_async_result.SimpleAsyncResult.propagateError. Otherwise it returns false.

Inherited Members

From ObjectG

setGObject
void setGObject(void* cObj, Flag!"Take" take)

Set the GObject of a D ObjectG wrapper.

cPtr
void* cPtr(Flag!"Dup" dup)

Get a pointer to the underlying C object.

ref_
void* ref_(void* gObj)

Calls g_object_ref() on a GObject.

unref
unref(void* gObj)

Calls g_object_unref() on a GObject.

getType
GType getType()

Get the GType of an object.

gType
GType gType [@property getter]

GObject GType property.

self
ObjectG self()

Convenience method to return this cast to a type. For use in D with statements.

getDObject
T getDObject(void* cptr, Flag!"Take" take)

Template to get the D object from a C GObject and cast it to the given D object type.

connectSignalClosure
ulong connectSignalClosure(string signalDetail, DClosure closure, Flag!"After" after)

Connect a D closure to an object signal.

setProperty
void setProperty(string propertyName, T val)

Template for setting a GObject property.

getProperty
T getProperty(string propertyName)

Template for getting a GObject property.

compatControl
size_t compatControl(size_t what, void* data)
bindProperty
gobject.binding.Binding bindProperty(string sourceProperty, gobject.object.ObjectG target, string targetProperty, gobject.types.BindingFlags flags)

Creates a binding between source_property on source and target_property on target.

bindPropertyFull
gobject.binding.Binding bindPropertyFull(string sourceProperty, gobject.object.ObjectG target, string targetProperty, gobject.types.BindingFlags flags, gobject.closure.Closure transformTo, gobject.closure.Closure transformFrom)

Creates a binding between source_property on source and target_property on target, allowing you to set the transformation functions to be used by the binding.

forceFloating
void forceFloating()

This function is intended for #GObject implementations to re-enforce a floating[floating-ref] object reference. Doing this is seldom required: all #GInitiallyUnowneds are created with a floating reference which usually just needs to be sunken by calling gobject.object.ObjectG.refSink.

freezeNotify
void freezeNotify()

Increases the freeze count on object. If the freeze count is non-zero, the emission of "notify" signals on object is stopped. The signals are queued until the freeze count is decreased to zero. Duplicate notifications are squashed so that at most one #GObject::notify signal is emitted for each property modified while the object is frozen.

getData
void* getData(string key)

Gets a named field from the objects table of associations (see gobject.object.ObjectG.setData).

getProperty
void getProperty(string propertyName, gobject.value.Value value)

Gets a property of an object.

getQdata
void* getQdata(glib.types.Quark quark)

This function gets back user data pointers stored via gobject.object.ObjectG.setQdata.

getv
void getv(string[] names, gobject.value.Value[] values)

Gets n_properties properties for an object. Obtained properties will be set to values. All properties must be valid. Warnings will be emitted and undefined behaviour may result if invalid properties are passed in.

isFloating
bool isFloating()

Checks whether object has a floating[floating-ref] reference.

notify
void notify(string propertyName)

Emits a "notify" signal for the property property_name on object.

notifyByPspec
void notifyByPspec(gobject.param_spec.ParamSpec pspec)

Emits a "notify" signal for the property specified by pspec on object.

refSink
gobject.object.ObjectG refSink()

Increase the reference count of object, and possibly remove the floating[floating-ref] reference, if object has a floating reference.

runDispose
void runDispose()

Releases all references to other objects. This can be used to break reference cycles.

setData
void setData(string key, void* data)

Each object carries around a table of associations from strings to pointers. This function lets you set an association.

setProperty
void setProperty(string propertyName, gobject.value.Value value)

Sets a property on an object.

stealData
void* stealData(string key)

Remove a specified datum from the object's data associations, without invoking the association's destroy handler.

stealQdata
void* stealQdata(glib.types.Quark quark)

This function gets back user data pointers stored via gobject.object.ObjectG.setQdata and removes the data from object without invoking its destroy() function (if any was set). Usually, calling this function is only required to update user data pointers with a destroy notifier, for example:

thawNotify
void thawNotify()

Reverts the effect of a previous call to gobject.object.ObjectG.freezeNotify. The freeze count is decreased on object and when it reaches zero, queued "notify" signals are emitted.

watchClosure
void watchClosure(gobject.closure.Closure closure)

This function essentially limits the life time of the closure to the life time of the object. That is, when the object is finalized, the closure is invalidated by calling gobject.closure.Closure.invalidate on it, in order to prevent invocations of the closure with a finalized (nonexisting) object. Also, gobject.object.ObjectG.ref_ and gobject.object.ObjectG.unref are added as marshal guards to the closure, to ensure that an extra reference count is held on object during invocation of the closure. Usually, this function will be called on closures that use this object as closure data.

connectNotify
ulong connectNotify(string detail, T callback, Flag!"After" after)

Connect to Notify signal.

From AsyncResult

getSourceObject
gobject.object.ObjectG getSourceObject()

Gets the source object from a #GAsyncResult.

getUserData
void* getUserData()

Gets the user data from a #GAsyncResult.

isTagged
bool isTagged(void* sourceTag)

Checks if res has the given source_tag (generally a function pointer indicating the function res was created by).

legacyPropagateError
bool legacyPropagateError()

If res is a #GSimpleAsyncResult, this is equivalent to gio.simple_async_result.SimpleAsyncResult.propagateError. Otherwise it returns false.