Gio.Task.prototype.set_return_on_cancel
function set_return_on_cancel(return_on_cancel: Boolean): Boolean { // Gjs wrapper for g_task_set_return_on_cancel() }
Sets or clears task's return-on-cancel flag. This is only meaningful for tasks run via Gio.Task.run_in_thread or Gio.Task.run_in_thread_sync.
If return_on_cancel is true, then cancelling task's Gio.Cancellable will immediately cause it to return, as though the task's Gio.TaskThreadFunc had called Gio.Task.prototype.return_error_if_cancelled and then returned.
This allows you to create a cancellable wrapper around an uninterruptable function. The Gio.TaskThreadFunc just needs to be careful that it does not modify any externally-visible state after it has been cancelled. To do that, the thread should call Gio.Task.prototype.set_return_on_cancel again to (atomically) set return-on-cancel false before making externally-visible changes; if the task gets cancelled before the return-on-cancel flag could be changed, Gio.Task.prototype.set_return_on_cancel will indicate this by returning false.
You can disable and re-enable this flag multiple times if you wish. If the task's Gio.Cancellable is cancelled while return-on-cancel is false, then calling Gio.Task.prototype.set_return_on_cancel to set it true again will cause the task to be cancelled at that point.
If the task's Gio.Cancellable is already cancelled before you call Gio.Task.run_in_thread/Gio.Task.run_in_thread_sync, then the Gio.TaskThreadFunc will still be run (for consistency), but the task will also be completed right away.
Since 2.36
- return_on_cancel
whether the task returns automatically when it is cancelled.
- Returns
true if task's return-on-cancel flag was changed to match return_on_cancel. false if task has already been cancelled.