Gio.Task.new
function new(source_object: GObject.Object, cancellable: Gio.Cancellable, callback: Gio.AsyncReadyCallback): Gio.Task { // Gjs wrapper for g_task_new() }
Creates a Gio.Task 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 Gio.Task around throughout the asynchronous operation. You can use Gio.Task.prototype.set_task_data to attach task-specific data to the object, which you can retrieve later via Gio.Task.prototype.get_task_data.
By default, if cancellable is cancelled, then the return value of the task will always be Gio.IOErrorEnum.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 Gio.Task.prototype.set_check_cancellable to change it.
Since 2.36
- source_object
the GObject.Object that owns this task, or null.
- cancellable
optional Gio.Cancellable object, null to ignore.
- callback
- Returns
a Gio.Task.