set_return_on_cancel
Description:
Sets or clears this's return-on-cancel flag.
This is only meaningful for tasks run via run_in_thread or run_in_thread_sync.
If return_on_cancel
is true, then cancelling this's
Cancellable will immediately cause it to return, as though the task's
TaskThreadFunc had called
return_error_if_cancelled and then returned.
This allows you to create a cancellable wrapper around an uninterruptible function. The 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 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, 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 Cancellable is cancelled while return-on-cancel is false, then calling set_return_on_cancel to set it true again will cause the task to be cancelled at that point.
If the task's Cancellable is already cancelled before you call run_in_thread/g_task_run_in_thread_sync(), then the TaskThreadFunc will still be run (for consistency), but the task will also be completed right away.
Parameters:
this |
the Task |
return_on_cancel |
whether the task returns automatically when it is cancelled. |
Returns:
true if this's return-on-cancel flag was changed to match |