Method

GioTaskset_return_on_cancel

since: 2.36

Declaration [src]

gboolean
g_task_set_return_on_cancel (
  GTask* task,
  gboolean return_on_cancel
)

Description [src]

Sets or clears tasks return-on-cancel flag. This is only meaningful for tasks run via g_task_run_in_thread() or g_task_run_in_thread_sync().

If return_on_cancel is TRUE, then cancelling tasks GCancellable will immediately cause it to return, as though the task’s GTaskThreadFunc had called g_task_return_error_if_cancelled() 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 g_task_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, g_task_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 GCancellable is cancelled while return-on-cancel is FALSE, then calling g_task_set_return_on_cancel() 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 g_task_run_in_thread()/g_task_run_in_thread_sync(), then the GTaskThreadFunc will still be run (for consistency), but the task will also be completed right away.

Available since: 2.36

Parameters

return_on_cancel

Type: gboolean

Whether the task returns automatically when it is cancelled.

Return value

Type: gboolean

TRUE if tasks return-on-cancel flag was changed to match return_on_cancel. FALSE if task has already been cancelled.