Task.setReturnOnCancel

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.

If return_on_cancel is true, then cancelling task's #GCancellable will immediately cause it to return, as though the task's #GTaskThreadFunc had called gio.task.Task.returnErrorIfCancelled and then returned.

This allows you to create a cancellable wrapper around an uninterruptible function. The #GTaskThreadFunc 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.Task.setReturnOnCancel 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.Task.setReturnOnCancel will indicate this by returning false.

You can disable and re-enable this flag multiple times if you wish. If the task's #GCancellable is cancelled while return-on-cancel is false, then calling gio.task.Task.setReturnOnCancel to set it true again will cause the task to be cancelled at that point.

If the task's #GCancellable is already cancelled before you call gio.task.Task.runInThread/gio.task.Task.runInThreadSync, then the #GTaskThreadFunc will still be run (for consistency), but the task will also be completed right away.

class Task
bool
setReturnOnCancel

Parameters

returnOnCancel bool

whether the task returns automatically when it is cancelled.

Return Value

Type: bool

true if task's return-on-cancel flag was changed to match return_on_cancel. false if task has already been cancelled.