Constructor

GioTasknew

since: 2.36

Declaration [src]

GTask*
g_task_new (
  GObject* source_object,
  GCancellable* cancellable,
  GAsyncReadyCallback callback,
  gpointer callback_data
)

Description [src]

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].

Call this in the “start” method of your asynchronous method, and pass the GTask around throughout the asynchronous operation. You can use g_task_set_task_data() to attach task-specific data to the object, which you can retrieve later via g_task_get_task_data().

By default, if cancellable is cancelled, then the return value of the task will always be G_IO_ERROR_CANCELLED, even if the task had already completed before the cancellation. This allows for simplified handling in cases where cancellation may imply that other objects that the task depends on have been destroyed. If you do not want this behavior, you can use g_task_set_check_cancellable() to change it.

Available since: 2.36

Parameters

source_object

Type: GObject

The GObject that owns this task, or NULL.

The argument can be NULL.
The data is owned by the caller of the function.
cancellable

Type: GCancellable

Optional GCancellable object, NULL to ignore.

The argument can be NULL.
The data is owned by the caller of the function.
callback

Type: GAsyncReadyCallback

A GAsyncReadyCallback.

The argument can be NULL.
callback_data

Type: gpointer

User data passed to callback.

The argument can be NULL.
The data is owned by the caller of the function.

Return value

Type: GTask

A GTask.

The caller of the function takes ownership of the data, and is responsible for freeing it.