⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.10
Server IP:
157.245.101.34
Server:
Linux skvinfotech-website 5.4.0-131-generic #147-Ubuntu SMP Fri Oct 14 17:07:22 UTC 2022 x86_64
Server Software:
Apache/2.4.41 (Ubuntu)
PHP Version:
7.4.33
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
proc
/
self
/
root
/
usr
/
share
/
gtk-doc
/
html
/
gio
/
View File Name :
GTask.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>GTask: GIO Reference Manual</title> <meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> <link rel="home" href="index.html" title="GIO Reference Manual"> <link rel="up" href="async.html" title="Asynchronous I/O"> <link rel="prev" href="GAsyncResult.html" title="GAsyncResult"> <link rel="next" href="gio-GIOScheduler.html" title="GIOScheduler"> <meta name="generator" content="GTK-Doc V1.32 (XML mode)"> <link rel="stylesheet" href="style.css" type="text/css"> </head> <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="5"><tr valign="middle"> <td width="100%" align="left" class="shortcuts"> <a href="#" class="shortcut">Top</a><span id="nav_description"> <span class="dim">|</span> <a href="#GTask.description" class="shortcut">Description</a></span><span id="nav_hierarchy"> <span class="dim">|</span> <a href="#GTask.object-hierarchy" class="shortcut">Object Hierarchy</a></span><span id="nav_interfaces"> <span class="dim">|</span> <a href="#GTask.implemented-interfaces" class="shortcut">Implemented Interfaces</a></span><span id="nav_properties"> <span class="dim">|</span> <a href="#GTask.properties" class="shortcut">Properties</a></span> </td> <td><a accesskey="h" href="index.html"><img src="home.png" width="16" height="16" border="0" alt="Home"></a></td> <td><a accesskey="u" href="async.html"><img src="up.png" width="16" height="16" border="0" alt="Up"></a></td> <td><a accesskey="p" href="GAsyncResult.html"><img src="left.png" width="16" height="16" border="0" alt="Prev"></a></td> <td><a accesskey="n" href="gio-GIOScheduler.html"><img src="right.png" width="16" height="16" border="0" alt="Next"></a></td> </tr></table> <div class="refentry"> <a name="GTask"></a><div class="titlepage"></div> <div class="refnamediv"><table width="100%"><tr> <td valign="top"> <h2><span class="refentrytitle"><a name="GTask.top_of_page"></a>GTask</span></h2> <p>GTask — Cancellable synchronous or asynchronous task and result</p> </td> <td class="gallery_image" valign="top" align="right"></td> </tr></table></div> <div class="refsect1"> <a name="GTask.functions"></a><h2>Functions</h2> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="functions_proto_type"> <col class="functions_proto_name"> </colgroup> <tbody> <tr> <td class="function_type"> <a class="link" href="GTask.html" title="GTask"><span class="returnvalue">GTask</span></a> * </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-new" title="g_task_new ()">g_task_new</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">void</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-set-task-data" title="g_task_set_task_data ()">g_task_set_task_data</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">void</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-set-priority" title="g_task_set_priority ()">g_task_set_priority</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">void</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-set-check-cancellable" title="g_task_set_check_cancellable ()">g_task_set_check_cancellable</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">gboolean</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-set-return-on-cancel" title="g_task_set_return_on_cancel ()">g_task_set_return_on_cancel</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">void</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-set-source-tag" title="g_task_set_source_tag ()">g_task_set_source_tag</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">void</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-set-name" title="g_task_set_name ()">g_task_set_name</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">void</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-report-error" title="g_task_report_error ()">g_task_report_error</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">void</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-report-new-error" title="g_task_report_new_error ()">g_task_report_new_error</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">gpointer</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-get-task-data" title="g_task_get_task_data ()">g_task_get_task_data</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">gint</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-get-priority" title="g_task_get_priority ()">g_task_get_priority</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <a class="link" href="GCancellable.html" title="GCancellable"><span class="returnvalue">GCancellable</span></a> * </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-get-cancellable" title="g_task_get_cancellable ()">g_task_get_cancellable</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">gboolean</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-get-check-cancellable" title="g_task_get_check_cancellable ()">g_task_get_check_cancellable</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">gboolean</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-get-return-on-cancel" title="g_task_get_return_on_cancel ()">g_task_get_return_on_cancel</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">GMainContext</span> * </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-get-context" title="g_task_get_context ()">g_task_get_context</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">gpointer</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-get-source-object" title="g_task_get_source_object ()">g_task_get_source_object</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">gpointer</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-get-source-tag" title="g_task_get_source_tag ()">g_task_get_source_tag</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type">const <span class="returnvalue">gchar</span> * </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-get-name" title="g_task_get_name ()">g_task_get_name</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">void</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-return-boolean" title="g_task_return_boolean ()">g_task_return_boolean</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">void</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-return-int" title="g_task_return_int ()">g_task_return_int</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">void</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-return-pointer" title="g_task_return_pointer ()">g_task_return_pointer</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">void</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-return-value" title="g_task_return_value ()">g_task_return_value</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">void</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-return-error" title="g_task_return_error ()">g_task_return_error</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">void</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-return-new-error" title="g_task_return_new_error ()">g_task_return_new_error</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">gboolean</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-return-error-if-cancelled" title="g_task_return_error_if_cancelled ()">g_task_return_error_if_cancelled</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">gboolean</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-propagate-boolean" title="g_task_propagate_boolean ()">g_task_propagate_boolean</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">gssize</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-propagate-int" title="g_task_propagate_int ()">g_task_propagate_int</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">gpointer</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-propagate-pointer" title="g_task_propagate_pointer ()">g_task_propagate_pointer</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">gboolean</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-propagate-value" title="g_task_propagate_value ()">g_task_propagate_value</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">gboolean</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-had-error" title="g_task_had_error ()">g_task_had_error</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">gboolean</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-get-completed" title="g_task_get_completed ()">g_task_get_completed</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">void</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-run-in-thread" title="g_task_run_in_thread ()">g_task_run_in_thread</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">void</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-run-in-thread-sync" title="g_task_run_in_thread_sync ()">g_task_run_in_thread_sync</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">void</span> </td> <td class="function_name"> <span class="c_punctuation">(</span><a class="link" href="GTask.html#GTaskThreadFunc" title="GTaskThreadFunc ()">*GTaskThreadFunc</a><span class="c_punctuation">)</span> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">void</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-attach-source" title="g_task_attach_source ()">g_task_attach_source</a> <span class="c_punctuation">()</span> </td> </tr> <tr> <td class="function_type"> <span class="returnvalue">gboolean</span> </td> <td class="function_name"> <a class="link" href="GTask.html#g-task-is-valid" title="g_task_is_valid ()">g_task_is_valid</a> <span class="c_punctuation">()</span> </td> </tr> </tbody> </table></div> </div> <div class="refsect1"> <a name="GTask.properties"></a><h2>Properties</h2> <div class="informaltable"><table class="informaltable" border="0"> <colgroup> <col width="150px" class="properties_type"> <col width="300px" class="properties_name"> <col width="200px" class="properties_flags"> </colgroup> <tbody><tr> <td class="property_type"><span class="type">gboolean</span></td> <td class="property_name"><a class="link" href="GTask.html#GTask--completed" title="The “completed” property">completed</a></td> <td class="property_flags">Read</td> </tr></tbody> </table></div> </div> <div class="refsect1"> <a name="GTask.other"></a><h2>Types and Values</h2> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="other_proto_type"> <col class="other_proto_name"> </colgroup> <tbody><tr> <td class="datatype_keyword"> </td> <td class="function_name"><a class="link" href="GTask.html#GTask-struct" title="GTask">GTask</a></td> </tr></tbody> </table></div> </div> <div class="refsect1"> <a name="GTask.object-hierarchy"></a><h2>Object Hierarchy</h2> <pre class="screen"> GObject <span class="lineart">╰──</span> GTask </pre> </div> <div class="refsect1"> <a name="GTask.implemented-interfaces"></a><h2>Implemented Interfaces</h2> <p> GTask implements <a class="link" href="GAsyncResult.html" title="GAsyncResult">GAsyncResult</a>.</p> </div> <div class="refsect1"> <a name="GTask.includes"></a><h2>Includes</h2> <pre class="synopsis">#include <gio/gio.h> </pre> </div> <div class="refsect1"> <a name="GTask.description"></a><h2>Description</h2> <p>A <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> represents and manages a cancellable "task".</p> <div class="refsect3"> <a name="id-1.4.5.4.9.3"></a><h4>Asynchronous operations</h4> <p>The most common usage of <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> is as a <a class="link" href="GAsyncResult.html" title="GAsyncResult"><span class="type">GAsyncResult</span></a>, to manage data during an asynchronous operation. You call <a class="link" href="GTask.html#g-task-new" title="g_task_new ()"><code class="function">g_task_new()</code></a> in the "start" method, followed by <a class="link" href="GTask.html#g-task-set-task-data" title="g_task_set_task_data ()"><code class="function">g_task_set_task_data()</code></a> and the like if you need to keep some additional data associated with the task, and then pass the task object around through your asynchronous operation. Eventually, you will call a method such as <a class="link" href="GTask.html#g-task-return-pointer" title="g_task_return_pointer ()"><code class="function">g_task_return_pointer()</code></a> or <a class="link" href="GTask.html#g-task-return-error" title="g_task_return_error ()"><code class="function">g_task_return_error()</code></a>, which will save the value you give it and then invoke the task's callback function in the thread-default main context where it was created (waiting until the next iteration of the main loop first, if necessary). The caller will pass the <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> back to the operation's finish function (as a <a class="link" href="GAsyncResult.html" title="GAsyncResult"><span class="type">GAsyncResult</span></a>), and you can use <a class="link" href="GTask.html#g-task-propagate-pointer" title="g_task_propagate_pointer ()"><code class="function">g_task_propagate_pointer()</code></a> or the like to extract the return value.</p> <p>Here is an example for using GTask as a GAsyncResult:</p> <div class="informalexample"> <table class="listing_frame" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td class="listing_lines" align="right"><pre>1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91</pre></td> <td class="listing_code"><pre class="programlisting"><span class="k">typedef</span> <span class="k">struct</span> <span class="p">{</span> <span class="n">CakeFrostingType</span> <span class="n">frosting</span><span class="p">;</span> <span class="kt">char</span> <span class="o">*</span><span class="n">message</span><span class="p">;</span> <span class="p">}</span> <span class="n">DecorationData</span><span class="p">;</span> <span class="k">static</span> <span class="kt">void</span> <span class="nf">decoration_data_free</span> <span class="p">(</span><span class="n">DecorationData</span> <span class="o">*</span><span class="n">decoration</span><span class="p">)</span> <span class="p">{</span> <span class="n">g_free</span> <span class="p">(</span><span class="n">decoration</span><span class="o">-></span><span class="n">message</span><span class="p">);</span> <span class="n">g_slice_free</span> <span class="p">(</span><span class="n">DecorationData</span><span class="p">,</span> <span class="n">decoration</span><span class="p">);</span> <span class="p">}</span> <span class="k">static</span> <span class="kt">void</span> <span class="nf">baked_cb</span> <span class="p">(</span><span class="n">Cake</span> <span class="o">*</span><span class="n">cake</span><span class="p">,</span> <span class="n">gpointer</span> <span class="n">user_data</span><span class="p">)</span> <span class="p">{</span> <span class="n">GTask</span> <span class="o">*</span><span class="n">task</span> <span class="o">=</span> <span class="n">user_data</span><span class="p">;</span> <span class="n">DecorationData</span> <span class="o">*</span><span class="n">decoration</span> <span class="o">=</span> <span class="n">g_task_get_task_data</span> <span class="p">(</span><span class="n">task</span><span class="p">);</span> <span class="n">GError</span> <span class="o">*</span><span class="n">error</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span> <span class="k">if</span> <span class="p">(</span><span class="n">cake</span> <span class="o">==</span> <span class="nb">NULL</span><span class="p">)</span> <span class="p">{</span> <span class="n">g_task_return_new_error</span> <span class="p">(</span><span class="n">task</span><span class="p">,</span> <span class="n">BAKER_ERROR</span><span class="p">,</span> <span class="n">BAKER_ERROR_NO_FLOUR</span><span class="p">,</span> <span class="s">"Go to the supermarket"</span><span class="p">);</span> <span class="n">g_object_unref</span> <span class="p">(</span><span class="n">task</span><span class="p">);</span> <span class="k">return</span><span class="p">;</span> <span class="p">}</span> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">cake_decorate</span> <span class="p">(</span><span class="n">cake</span><span class="p">,</span> <span class="n">decoration</span><span class="o">-></span><span class="n">frosting</span><span class="p">,</span> <span class="n">decoration</span><span class="o">-></span><span class="n">message</span><span class="p">,</span> <span class="o">&</span><span class="n">error</span><span class="p">))</span> <span class="p">{</span> <span class="n">g_object_unref</span> <span class="p">(</span><span class="n">cake</span><span class="p">);</span> <span class="c1">// g_task_return_error() takes ownership of error</span> <span class="n">g_task_return_error</span> <span class="p">(</span><span class="n">task</span><span class="p">,</span> <span class="n">error</span><span class="p">);</span> <span class="n">g_object_unref</span> <span class="p">(</span><span class="n">task</span><span class="p">);</span> <span class="k">return</span><span class="p">;</span> <span class="p">}</span> <span class="n">g_task_return_pointer</span> <span class="p">(</span><span class="n">task</span><span class="p">,</span> <span class="n">cake</span><span class="p">,</span> <span class="n">g_object_unref</span><span class="p">);</span> <span class="n">g_object_unref</span> <span class="p">(</span><span class="n">task</span><span class="p">);</span> <span class="p">}</span> <span class="kt">void</span> <span class="nf">baker_bake_cake_async</span> <span class="p">(</span><span class="n">Baker</span> <span class="o">*</span><span class="n">self</span><span class="p">,</span> <span class="n">guint</span> <span class="n">radius</span><span class="p">,</span> <span class="n">CakeFlavor</span> <span class="n">flavor</span><span class="p">,</span> <span class="n">CakeFrostingType</span> <span class="n">frosting</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">message</span><span class="p">,</span> <span class="n">GCancellable</span> <span class="o">*</span><span class="n">cancellable</span><span class="p">,</span> <span class="n">GAsyncReadyCallback</span> <span class="n">callback</span><span class="p">,</span> <span class="n">gpointer</span> <span class="n">user_data</span><span class="p">)</span> <span class="p">{</span> <span class="n">GTask</span> <span class="o">*</span><span class="n">task</span><span class="p">;</span> <span class="n">DecorationData</span> <span class="o">*</span><span class="n">decoration</span><span class="p">;</span> <span class="n">Cake</span> <span class="o">*</span><span class="n">cake</span><span class="p">;</span> <span class="n">task</span> <span class="o">=</span> <span class="n">g_task_new</span> <span class="p">(</span><span class="n">self</span><span class="p">,</span> <span class="n">cancellable</span><span class="p">,</span> <span class="n">callback</span><span class="p">,</span> <span class="n">user_data</span><span class="p">);</span> <span class="k">if</span> <span class="p">(</span><span class="n">radius</span> <span class="o"><</span> <span class="mi">3</span><span class="p">)</span> <span class="p">{</span> <span class="n">g_task_return_new_error</span> <span class="p">(</span><span class="n">task</span><span class="p">,</span> <span class="n">BAKER_ERROR</span><span class="p">,</span> <span class="n">BAKER_ERROR_TOO_SMALL</span><span class="p">,</span> <span class="s">"%ucm radius cakes are silly"</span><span class="p">,</span> <span class="n">radius</span><span class="p">);</span> <span class="n">g_object_unref</span> <span class="p">(</span><span class="n">task</span><span class="p">);</span> <span class="k">return</span><span class="p">;</span> <span class="p">}</span> <span class="n">cake</span> <span class="o">=</span> <span class="n">_baker_get_cached_cake</span> <span class="p">(</span><span class="n">self</span><span class="p">,</span> <span class="n">radius</span><span class="p">,</span> <span class="n">flavor</span><span class="p">,</span> <span class="n">frosting</span><span class="p">,</span> <span class="n">message</span><span class="p">);</span> <span class="k">if</span> <span class="p">(</span><span class="n">cake</span> <span class="o">!=</span> <span class="nb">NULL</span><span class="p">)</span> <span class="p">{</span> <span class="c1">// _baker_get_cached_cake() returns a reffed cake</span> <span class="n">g_task_return_pointer</span> <span class="p">(</span><span class="n">task</span><span class="p">,</span> <span class="n">cake</span><span class="p">,</span> <span class="n">g_object_unref</span><span class="p">);</span> <span class="n">g_object_unref</span> <span class="p">(</span><span class="n">task</span><span class="p">);</span> <span class="k">return</span><span class="p">;</span> <span class="p">}</span> <span class="n">decoration</span> <span class="o">=</span> <span class="n">g_slice_new</span> <span class="p">(</span><span class="n">DecorationData</span><span class="p">);</span> <span class="n">decoration</span><span class="o">-></span><span class="n">frosting</span> <span class="o">=</span> <span class="n">frosting</span><span class="p">;</span> <span class="n">decoration</span><span class="o">-></span><span class="n">message</span> <span class="o">=</span> <span class="n">g_strdup</span> <span class="p">(</span><span class="n">message</span><span class="p">);</span> <span class="n">g_task_set_task_data</span> <span class="p">(</span><span class="n">task</span><span class="p">,</span> <span class="n">decoration</span><span class="p">,</span> <span class="p">(</span><span class="n">GDestroyNotify</span><span class="p">)</span> <span class="n">decoration_data_free</span><span class="p">);</span> <span class="n">_baker_begin_cake</span> <span class="p">(</span><span class="n">self</span><span class="p">,</span> <span class="n">radius</span><span class="p">,</span> <span class="n">flavor</span><span class="p">,</span> <span class="n">cancellable</span><span class="p">,</span> <span class="n">baked_cb</span><span class="p">,</span> <span class="n">task</span><span class="p">);</span> <span class="p">}</span> <span class="n">Cake</span> <span class="o">*</span> <span class="nf">baker_bake_cake_finish</span> <span class="p">(</span><span class="n">Baker</span> <span class="o">*</span><span class="n">self</span><span class="p">,</span> <span class="n">GAsyncResult</span> <span class="o">*</span><span class="n">result</span><span class="p">,</span> <span class="n">GError</span> <span class="o">**</span><span class="n">error</span><span class="p">)</span> <span class="p">{</span> <span class="n">g_return_val_if_fail</span> <span class="p">(</span><span class="n">g_task_is_valid</span> <span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">self</span><span class="p">),</span> <span class="nb">NULL</span><span class="p">);</span> <span class="k">return</span> <span class="n">g_task_propagate_pointer</span> <span class="p">(</span><span class="n">G_TASK</span> <span class="p">(</span><span class="n">result</span><span class="p">),</span> <span class="n">error</span><span class="p">);</span> <span class="p">}</span></pre></td> </tr> </tbody> </table> </div> <p></p> </div> <div class="refsect3"> <a name="id-1.4.5.4.9.4"></a><h4>Chained asynchronous operations</h4> <p><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> also tries to simplify asynchronous operations that internally chain together several smaller asynchronous operations. <a class="link" href="GTask.html#g-task-get-cancellable" title="g_task_get_cancellable ()"><code class="function">g_task_get_cancellable()</code></a>, <a class="link" href="GTask.html#g-task-get-context" title="g_task_get_context ()"><code class="function">g_task_get_context()</code></a>, and <a class="link" href="GTask.html#g-task-get-priority" title="g_task_get_priority ()"><code class="function">g_task_get_priority()</code></a> allow you to get back the task's <a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a>, <span class="type">GMainContext</span>, and <a class="link" href="GAsyncResult.html#io-priority" title="I/O Priority">I/O priority</a> when starting a new subtask, so you don't have to keep track of them yourself. <a class="link" href="GTask.html#g-task-attach-source" title="g_task_attach_source ()"><code class="function">g_task_attach_source()</code></a> simplifies the case of waiting for a source to fire (automatically using the correct <span class="type">GMainContext</span> and priority).</p> <p>Here is an example for chained asynchronous operations:</p> <div class="informalexample"> <table class="listing_frame" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td class="listing_lines" align="right"><pre>1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123</pre></td> <td class="listing_code"><pre class="programlisting"><span class="k">typedef</span> <span class="k">struct</span> <span class="p">{</span> <span class="n">Cake</span> <span class="o">*</span><span class="n">cake</span><span class="p">;</span> <span class="n">CakeFrostingType</span> <span class="n">frosting</span><span class="p">;</span> <span class="kt">char</span> <span class="o">*</span><span class="n">message</span><span class="p">;</span> <span class="p">}</span> <span class="n">BakingData</span><span class="p">;</span> <span class="k">static</span> <span class="kt">void</span> <span class="nf">decoration_data_free</span> <span class="p">(</span><span class="n">BakingData</span> <span class="o">*</span><span class="n">bd</span><span class="p">)</span> <span class="p">{</span> <span class="k">if</span> <span class="p">(</span><span class="n">bd</span><span class="o">-></span><span class="n">cake</span><span class="p">)</span> <span class="n">g_object_unref</span> <span class="p">(</span><span class="n">bd</span><span class="o">-></span><span class="n">cake</span><span class="p">);</span> <span class="n">g_free</span> <span class="p">(</span><span class="n">bd</span><span class="o">-></span><span class="n">message</span><span class="p">);</span> <span class="n">g_slice_free</span> <span class="p">(</span><span class="n">BakingData</span><span class="p">,</span> <span class="n">bd</span><span class="p">);</span> <span class="p">}</span> <span class="k">static</span> <span class="kt">void</span> <span class="nf">decorated_cb</span> <span class="p">(</span><span class="n">Cake</span> <span class="o">*</span><span class="n">cake</span><span class="p">,</span> <span class="n">GAsyncResult</span> <span class="o">*</span><span class="n">result</span><span class="p">,</span> <span class="n">gpointer</span> <span class="n">user_data</span><span class="p">)</span> <span class="p">{</span> <span class="n">GTask</span> <span class="o">*</span><span class="n">task</span> <span class="o">=</span> <span class="n">user_data</span><span class="p">;</span> <span class="n">GError</span> <span class="o">*</span><span class="n">error</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span> <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">cake_decorate_finish</span> <span class="p">(</span><span class="n">cake</span><span class="p">,</span> <span class="n">result</span><span class="p">,</span> <span class="o">&</span><span class="n">error</span><span class="p">))</span> <span class="p">{</span> <span class="n">g_object_unref</span> <span class="p">(</span><span class="n">cake</span><span class="p">);</span> <span class="n">g_task_return_error</span> <span class="p">(</span><span class="n">task</span><span class="p">,</span> <span class="n">error</span><span class="p">);</span> <span class="n">g_object_unref</span> <span class="p">(</span><span class="n">task</span><span class="p">);</span> <span class="k">return</span><span class="p">;</span> <span class="p">}</span> <span class="c1">// baking_data_free() will drop its ref on the cake, so we have to</span> <span class="c1">// take another here to give to the caller.</span> <span class="n">g_task_return_pointer</span> <span class="p">(</span><span class="n">task</span><span class="p">,</span> <span class="n">g_object_ref</span> <span class="p">(</span><span class="n">cake</span><span class="p">),</span> <span class="n">g_object_unref</span><span class="p">);</span> <span class="n">g_object_unref</span> <span class="p">(</span><span class="n">task</span><span class="p">);</span> <span class="p">}</span> <span class="k">static</span> <span class="n">gboolean</span> <span class="nf">decorator_ready</span> <span class="p">(</span><span class="n">gpointer</span> <span class="n">user_data</span><span class="p">)</span> <span class="p">{</span> <span class="n">GTask</span> <span class="o">*</span><span class="n">task</span> <span class="o">=</span> <span class="n">user_data</span><span class="p">;</span> <span class="n">BakingData</span> <span class="o">*</span><span class="n">bd</span> <span class="o">=</span> <span class="n">g_task_get_task_data</span> <span class="p">(</span><span class="n">task</span><span class="p">);</span> <span class="n">cake_decorate_async</span> <span class="p">(</span><span class="n">bd</span><span class="o">-></span><span class="n">cake</span><span class="p">,</span> <span class="n">bd</span><span class="o">-></span><span class="n">frosting</span><span class="p">,</span> <span class="n">bd</span><span class="o">-></span><span class="n">message</span><span class="p">,</span> <span class="n">g_task_get_cancellable</span> <span class="p">(</span><span class="n">task</span><span class="p">),</span> <span class="n">decorated_cb</span><span class="p">,</span> <span class="n">task</span><span class="p">);</span> <span class="k">return</span> <span class="n">G_SOURCE_REMOVE</span><span class="p">;</span> <span class="p">}</span> <span class="k">static</span> <span class="kt">void</span> <span class="nf">baked_cb</span> <span class="p">(</span><span class="n">Cake</span> <span class="o">*</span><span class="n">cake</span><span class="p">,</span> <span class="n">gpointer</span> <span class="n">user_data</span><span class="p">)</span> <span class="p">{</span> <span class="n">GTask</span> <span class="o">*</span><span class="n">task</span> <span class="o">=</span> <span class="n">user_data</span><span class="p">;</span> <span class="n">BakingData</span> <span class="o">*</span><span class="n">bd</span> <span class="o">=</span> <span class="n">g_task_get_task_data</span> <span class="p">(</span><span class="n">task</span><span class="p">);</span> <span class="n">GError</span> <span class="o">*</span><span class="n">error</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span> <span class="k">if</span> <span class="p">(</span><span class="n">cake</span> <span class="o">==</span> <span class="nb">NULL</span><span class="p">)</span> <span class="p">{</span> <span class="n">g_task_return_new_error</span> <span class="p">(</span><span class="n">task</span><span class="p">,</span> <span class="n">BAKER_ERROR</span><span class="p">,</span> <span class="n">BAKER_ERROR_NO_FLOUR</span><span class="p">,</span> <span class="s">"Go to the supermarket"</span><span class="p">);</span> <span class="n">g_object_unref</span> <span class="p">(</span><span class="n">task</span><span class="p">);</span> <span class="k">return</span><span class="p">;</span> <span class="p">}</span> <span class="n">bd</span><span class="o">-></span><span class="n">cake</span> <span class="o">=</span> <span class="n">cake</span><span class="p">;</span> <span class="c1">// Bail out now if the user has already cancelled</span> <span class="k">if</span> <span class="p">(</span><span class="n">g_task_return_error_if_cancelled</span> <span class="p">(</span><span class="n">task</span><span class="p">))</span> <span class="p">{</span> <span class="n">g_object_unref</span> <span class="p">(</span><span class="n">task</span><span class="p">);</span> <span class="k">return</span><span class="p">;</span> <span class="p">}</span> <span class="k">if</span> <span class="p">(</span><span class="n">cake_decorator_available</span> <span class="p">(</span><span class="n">cake</span><span class="p">))</span> <span class="n">decorator_ready</span> <span class="p">(</span><span class="n">task</span><span class="p">);</span> <span class="k">else</span> <span class="p">{</span> <span class="n">GSource</span> <span class="o">*</span><span class="n">source</span><span class="p">;</span> <span class="n">source</span> <span class="o">=</span> <span class="n">cake_decorator_wait_source_new</span> <span class="p">(</span><span class="n">cake</span><span class="p">);</span> <span class="c1">// Attach @source to @task's GMainContext and have it call</span> <span class="c1">// decorator_ready() when it is ready.</span> <span class="n">g_task_attach_source</span> <span class="p">(</span><span class="n">task</span><span class="p">,</span> <span class="n">source</span><span class="p">,</span> <span class="n">decorator_ready</span><span class="p">);</span> <span class="n">g_source_unref</span> <span class="p">(</span><span class="n">source</span><span class="p">);</span> <span class="p">}</span> <span class="p">}</span> <span class="kt">void</span> <span class="nf">baker_bake_cake_async</span> <span class="p">(</span><span class="n">Baker</span> <span class="o">*</span><span class="n">self</span><span class="p">,</span> <span class="n">guint</span> <span class="n">radius</span><span class="p">,</span> <span class="n">CakeFlavor</span> <span class="n">flavor</span><span class="p">,</span> <span class="n">CakeFrostingType</span> <span class="n">frosting</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">message</span><span class="p">,</span> <span class="n">gint</span> <span class="n">priority</span><span class="p">,</span> <span class="n">GCancellable</span> <span class="o">*</span><span class="n">cancellable</span><span class="p">,</span> <span class="n">GAsyncReadyCallback</span> <span class="n">callback</span><span class="p">,</span> <span class="n">gpointer</span> <span class="n">user_data</span><span class="p">)</span> <span class="p">{</span> <span class="n">GTask</span> <span class="o">*</span><span class="n">task</span><span class="p">;</span> <span class="n">BakingData</span> <span class="o">*</span><span class="n">bd</span><span class="p">;</span> <span class="n">task</span> <span class="o">=</span> <span class="n">g_task_new</span> <span class="p">(</span><span class="n">self</span><span class="p">,</span> <span class="n">cancellable</span><span class="p">,</span> <span class="n">callback</span><span class="p">,</span> <span class="n">user_data</span><span class="p">);</span> <span class="n">g_task_set_priority</span> <span class="p">(</span><span class="n">task</span><span class="p">,</span> <span class="n">priority</span><span class="p">);</span> <span class="n">bd</span> <span class="o">=</span> <span class="n">g_slice_new0</span> <span class="p">(</span><span class="n">BakingData</span><span class="p">);</span> <span class="n">bd</span><span class="o">-></span><span class="n">frosting</span> <span class="o">=</span> <span class="n">frosting</span><span class="p">;</span> <span class="n">bd</span><span class="o">-></span><span class="n">message</span> <span class="o">=</span> <span class="n">g_strdup</span> <span class="p">(</span><span class="n">message</span><span class="p">);</span> <span class="n">g_task_set_task_data</span> <span class="p">(</span><span class="n">task</span><span class="p">,</span> <span class="n">bd</span><span class="p">,</span> <span class="p">(</span><span class="n">GDestroyNotify</span><span class="p">)</span> <span class="n">baking_data_free</span><span class="p">);</span> <span class="n">_baker_begin_cake</span> <span class="p">(</span><span class="n">self</span><span class="p">,</span> <span class="n">radius</span><span class="p">,</span> <span class="n">flavor</span><span class="p">,</span> <span class="n">cancellable</span><span class="p">,</span> <span class="n">baked_cb</span><span class="p">,</span> <span class="n">task</span><span class="p">);</span> <span class="p">}</span> <span class="n">Cake</span> <span class="o">*</span> <span class="nf">baker_bake_cake_finish</span> <span class="p">(</span><span class="n">Baker</span> <span class="o">*</span><span class="n">self</span><span class="p">,</span> <span class="n">GAsyncResult</span> <span class="o">*</span><span class="n">result</span><span class="p">,</span> <span class="n">GError</span> <span class="o">**</span><span class="n">error</span><span class="p">)</span> <span class="p">{</span> <span class="n">g_return_val_if_fail</span> <span class="p">(</span><span class="n">g_task_is_valid</span> <span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">self</span><span class="p">),</span> <span class="nb">NULL</span><span class="p">);</span> <span class="k">return</span> <span class="n">g_task_propagate_pointer</span> <span class="p">(</span><span class="n">G_TASK</span> <span class="p">(</span><span class="n">result</span><span class="p">),</span> <span class="n">error</span><span class="p">);</span> <span class="p">}</span></pre></td> </tr> </tbody> </table> </div> <p></p> </div> <div class="refsect3"> <a name="id-1.4.5.4.9.5"></a><h4>Asynchronous operations from synchronous ones</h4> <p>You can use <a class="link" href="GTask.html#g-task-run-in-thread" title="g_task_run_in_thread ()"><code class="function">g_task_run_in_thread()</code></a> to turn a synchronous operation into an asynchronous one, by running it in a thread. When it completes, the result will be dispatched to the thread-default main context where the <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> was created.</p> <p>Running a task in a thread:</p> <div class="informalexample"> <table class="listing_frame" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td class="listing_lines" align="right"><pre>1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67</pre></td> <td class="listing_code"><pre class="programlisting"><span class="k">typedef</span> <span class="k">struct</span> <span class="p">{</span> <span class="n">guint</span> <span class="n">radius</span><span class="p">;</span> <span class="n">CakeFlavor</span> <span class="n">flavor</span><span class="p">;</span> <span class="n">CakeFrostingType</span> <span class="n">frosting</span><span class="p">;</span> <span class="kt">char</span> <span class="o">*</span><span class="n">message</span><span class="p">;</span> <span class="p">}</span> <span class="n">CakeData</span><span class="p">;</span> <span class="k">static</span> <span class="kt">void</span> <span class="nf">cake_data_free</span> <span class="p">(</span><span class="n">CakeData</span> <span class="o">*</span><span class="n">cake_data</span><span class="p">)</span> <span class="p">{</span> <span class="n">g_free</span> <span class="p">(</span><span class="n">cake_data</span><span class="o">-></span><span class="n">message</span><span class="p">);</span> <span class="n">g_slice_free</span> <span class="p">(</span><span class="n">CakeData</span><span class="p">,</span> <span class="n">cake_data</span><span class="p">);</span> <span class="p">}</span> <span class="k">static</span> <span class="kt">void</span> <span class="nf">bake_cake_thread</span> <span class="p">(</span><span class="n">GTask</span> <span class="o">*</span><span class="n">task</span><span class="p">,</span> <span class="n">gpointer</span> <span class="n">source_object</span><span class="p">,</span> <span class="n">gpointer</span> <span class="n">task_data</span><span class="p">,</span> <span class="n">GCancellable</span> <span class="o">*</span><span class="n">cancellable</span><span class="p">)</span> <span class="p">{</span> <span class="n">Baker</span> <span class="o">*</span><span class="n">self</span> <span class="o">=</span> <span class="n">source_object</span><span class="p">;</span> <span class="n">CakeData</span> <span class="o">*</span><span class="n">cake_data</span> <span class="o">=</span> <span class="n">task_data</span><span class="p">;</span> <span class="n">Cake</span> <span class="o">*</span><span class="n">cake</span><span class="p">;</span> <span class="n">GError</span> <span class="o">*</span><span class="n">error</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span> <span class="n">cake</span> <span class="o">=</span> <span class="n">bake_cake</span> <span class="p">(</span><span class="n">baker</span><span class="p">,</span> <span class="n">cake_data</span><span class="o">-></span><span class="n">radius</span><span class="p">,</span> <span class="n">cake_data</span><span class="o">-></span><span class="n">flavor</span><span class="p">,</span> <span class="n">cake_data</span><span class="o">-></span><span class="n">frosting</span><span class="p">,</span> <span class="n">cake_data</span><span class="o">-></span><span class="n">message</span><span class="p">,</span> <span class="n">cancellable</span><span class="p">,</span> <span class="o">&</span><span class="n">error</span><span class="p">);</span> <span class="k">if</span> <span class="p">(</span><span class="n">cake</span><span class="p">)</span> <span class="n">g_task_return_pointer</span> <span class="p">(</span><span class="n">task</span><span class="p">,</span> <span class="n">cake</span><span class="p">,</span> <span class="n">g_object_unref</span><span class="p">);</span> <span class="k">else</span> <span class="n">g_task_return_error</span> <span class="p">(</span><span class="n">task</span><span class="p">,</span> <span class="n">error</span><span class="p">);</span> <span class="p">}</span> <span class="kt">void</span> <span class="nf">baker_bake_cake_async</span> <span class="p">(</span><span class="n">Baker</span> <span class="o">*</span><span class="n">self</span><span class="p">,</span> <span class="n">guint</span> <span class="n">radius</span><span class="p">,</span> <span class="n">CakeFlavor</span> <span class="n">flavor</span><span class="p">,</span> <span class="n">CakeFrostingType</span> <span class="n">frosting</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">message</span><span class="p">,</span> <span class="n">GCancellable</span> <span class="o">*</span><span class="n">cancellable</span><span class="p">,</span> <span class="n">GAsyncReadyCallback</span> <span class="n">callback</span><span class="p">,</span> <span class="n">gpointer</span> <span class="n">user_data</span><span class="p">)</span> <span class="p">{</span> <span class="n">CakeData</span> <span class="o">*</span><span class="n">cake_data</span><span class="p">;</span> <span class="n">GTask</span> <span class="o">*</span><span class="n">task</span><span class="p">;</span> <span class="n">cake_data</span> <span class="o">=</span> <span class="n">g_slice_new</span> <span class="p">(</span><span class="n">CakeData</span><span class="p">);</span> <span class="n">cake_data</span><span class="o">-></span><span class="n">radius</span> <span class="o">=</span> <span class="n">radius</span><span class="p">;</span> <span class="n">cake_data</span><span class="o">-></span><span class="n">flavor</span> <span class="o">=</span> <span class="n">flavor</span><span class="p">;</span> <span class="n">cake_data</span><span class="o">-></span><span class="n">frosting</span> <span class="o">=</span> <span class="n">frosting</span><span class="p">;</span> <span class="n">cake_data</span><span class="o">-></span><span class="n">message</span> <span class="o">=</span> <span class="n">g_strdup</span> <span class="p">(</span><span class="n">message</span><span class="p">);</span> <span class="n">task</span> <span class="o">=</span> <span class="n">g_task_new</span> <span class="p">(</span><span class="n">self</span><span class="p">,</span> <span class="n">cancellable</span><span class="p">,</span> <span class="n">callback</span><span class="p">,</span> <span class="n">user_data</span><span class="p">);</span> <span class="n">g_task_set_task_data</span> <span class="p">(</span><span class="n">task</span><span class="p">,</span> <span class="n">cake_data</span><span class="p">,</span> <span class="p">(</span><span class="n">GDestroyNotify</span><span class="p">)</span> <span class="n">cake_data_free</span><span class="p">);</span> <span class="n">g_task_run_in_thread</span> <span class="p">(</span><span class="n">task</span><span class="p">,</span> <span class="n">bake_cake_thread</span><span class="p">);</span> <span class="n">g_object_unref</span> <span class="p">(</span><span class="n">task</span><span class="p">);</span> <span class="p">}</span> <span class="n">Cake</span> <span class="o">*</span> <span class="nf">baker_bake_cake_finish</span> <span class="p">(</span><span class="n">Baker</span> <span class="o">*</span><span class="n">self</span><span class="p">,</span> <span class="n">GAsyncResult</span> <span class="o">*</span><span class="n">result</span><span class="p">,</span> <span class="n">GError</span> <span class="o">**</span><span class="n">error</span><span class="p">)</span> <span class="p">{</span> <span class="n">g_return_val_if_fail</span> <span class="p">(</span><span class="n">g_task_is_valid</span> <span class="p">(</span><span class="n">result</span><span class="p">,</span> <span class="n">self</span><span class="p">),</span> <span class="nb">NULL</span><span class="p">);</span> <span class="k">return</span> <span class="n">g_task_propagate_pointer</span> <span class="p">(</span><span class="n">G_TASK</span> <span class="p">(</span><span class="n">result</span><span class="p">),</span> <span class="n">error</span><span class="p">);</span> <span class="p">}</span></pre></td> </tr> </tbody> </table> </div> <p></p> </div> <div class="refsect3"> <a name="id-1.4.5.4.9.6"></a><h4>Adding cancellability to uncancellable tasks</h4> <p>Finally, <a class="link" href="GTask.html#g-task-run-in-thread" title="g_task_run_in_thread ()"><code class="function">g_task_run_in_thread()</code></a> and <a class="link" href="GTask.html#g-task-run-in-thread-sync" title="g_task_run_in_thread_sync ()"><code class="function">g_task_run_in_thread_sync()</code></a> can be used to turn an uncancellable operation into a cancellable one. If you call <a class="link" href="GTask.html#g-task-set-return-on-cancel" title="g_task_set_return_on_cancel ()"><code class="function">g_task_set_return_on_cancel()</code></a>, passing <code class="literal">TRUE</code>, then if the task's <a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a> is cancelled, it will return control back to the caller immediately, while allowing the task thread to continue running in the background (and simply discarding its result when it finally does finish). Provided that the task thread is careful about how it uses locks and other externally-visible resources, this allows you to make "GLib-friendly" asynchronous and cancellable synchronous variants of blocking APIs.</p> <p>Cancelling a task:</p> <div class="informalexample"> <table class="listing_frame" border="0" cellpadding="0" cellspacing="0"> <tbody> <tr> <td class="listing_lines" align="right"><pre>1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88</pre></td> <td class="listing_code"><pre class="programlisting"><span class="k">static</span> <span class="kt">void</span> <span class="nf">bake_cake_thread</span> <span class="p">(</span><span class="n">GTask</span> <span class="o">*</span><span class="n">task</span><span class="p">,</span> <span class="n">gpointer</span> <span class="n">source_object</span><span class="p">,</span> <span class="n">gpointer</span> <span class="n">task_data</span><span class="p">,</span> <span class="n">GCancellable</span> <span class="o">*</span><span class="n">cancellable</span><span class="p">)</span> <span class="p">{</span> <span class="n">Baker</span> <span class="o">*</span><span class="n">self</span> <span class="o">=</span> <span class="n">source_object</span><span class="p">;</span> <span class="n">CakeData</span> <span class="o">*</span><span class="n">cake_data</span> <span class="o">=</span> <span class="n">task_data</span><span class="p">;</span> <span class="n">Cake</span> <span class="o">*</span><span class="n">cake</span><span class="p">;</span> <span class="n">GError</span> <span class="o">*</span><span class="n">error</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span> <span class="n">cake</span> <span class="o">=</span> <span class="n">bake_cake</span> <span class="p">(</span><span class="n">baker</span><span class="p">,</span> <span class="n">cake_data</span><span class="o">-></span><span class="n">radius</span><span class="p">,</span> <span class="n">cake_data</span><span class="o">-></span><span class="n">flavor</span><span class="p">,</span> <span class="n">cake_data</span><span class="o">-></span><span class="n">frosting</span><span class="p">,</span> <span class="n">cake_data</span><span class="o">-></span><span class="n">message</span><span class="p">,</span> <span class="o">&</span><span class="n">error</span><span class="p">);</span> <span class="k">if</span> <span class="p">(</span><span class="n">error</span><span class="p">)</span> <span class="p">{</span> <span class="n">g_task_return_error</span> <span class="p">(</span><span class="n">task</span><span class="p">,</span> <span class="n">error</span><span class="p">);</span> <span class="k">return</span><span class="p">;</span> <span class="p">}</span> <span class="c1">// If the task has already been cancelled, then we don't want to add</span> <span class="c1">// the cake to the cake cache. Likewise, we don't want to have the</span> <span class="c1">// task get cancelled in the middle of updating the cache.</span> <span class="c1">// g_task_set_return_on_cancel() will return %TRUE here if it managed</span> <span class="c1">// to disable return-on-cancel, or %FALSE if the task was cancelled</span> <span class="c1">// before it could.</span> <span class="k">if</span> <span class="p">(</span><span class="n">g_task_set_return_on_cancel</span> <span class="p">(</span><span class="n">task</span><span class="p">,</span> <span class="n">FALSE</span><span class="p">))</span> <span class="p">{</span> <span class="c1">// If the caller cancels at this point, their</span> <span class="c1">// GAsyncReadyCallback won't be invoked until we return,</span> <span class="c1">// so we don't have to worry that this code will run at</span> <span class="c1">// the same time as that code does. But if there were</span> <span class="c1">// other functions that might look at the cake cache,</span> <span class="c1">// then we'd probably need a GMutex here as well.</span> <span class="n">baker_add_cake_to_cache</span> <span class="p">(</span><span class="n">baker</span><span class="p">,</span> <span class="n">cake</span><span class="p">);</span> <span class="n">g_task_return_pointer</span> <span class="p">(</span><span class="n">task</span><span class="p">,</span> <span class="n">cake</span><span class="p">,</span> <span class="n">g_object_unref</span><span class="p">);</span> <span class="p">}</span> <span class="p">}</span> <span class="kt">void</span> <span class="nf">baker_bake_cake_async</span> <span class="p">(</span><span class="n">Baker</span> <span class="o">*</span><span class="n">self</span><span class="p">,</span> <span class="n">guint</span> <span class="n">radius</span><span class="p">,</span> <span class="n">CakeFlavor</span> <span class="n">flavor</span><span class="p">,</span> <span class="n">CakeFrostingType</span> <span class="n">frosting</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">message</span><span class="p">,</span> <span class="n">GCancellable</span> <span class="o">*</span><span class="n">cancellable</span><span class="p">,</span> <span class="n">GAsyncReadyCallback</span> <span class="n">callback</span><span class="p">,</span> <span class="n">gpointer</span> <span class="n">user_data</span><span class="p">)</span> <span class="p">{</span> <span class="n">CakeData</span> <span class="o">*</span><span class="n">cake_data</span><span class="p">;</span> <span class="n">GTask</span> <span class="o">*</span><span class="n">task</span><span class="p">;</span> <span class="n">cake_data</span> <span class="o">=</span> <span class="n">g_slice_new</span> <span class="p">(</span><span class="n">CakeData</span><span class="p">);</span> <span class="p">...</span> <span class="n">task</span> <span class="o">=</span> <span class="n">g_task_new</span> <span class="p">(</span><span class="n">self</span><span class="p">,</span> <span class="n">cancellable</span><span class="p">,</span> <span class="n">callback</span><span class="p">,</span> <span class="n">user_data</span><span class="p">);</span> <span class="n">g_task_set_task_data</span> <span class="p">(</span><span class="n">task</span><span class="p">,</span> <span class="n">cake_data</span><span class="p">,</span> <span class="p">(</span><span class="n">GDestroyNotify</span><span class="p">)</span> <span class="n">cake_data_free</span><span class="p">);</span> <span class="n">g_task_set_return_on_cancel</span> <span class="p">(</span><span class="n">task</span><span class="p">,</span> <span class="n">TRUE</span><span class="p">);</span> <span class="n">g_task_run_in_thread</span> <span class="p">(</span><span class="n">task</span><span class="p">,</span> <span class="n">bake_cake_thread</span><span class="p">);</span> <span class="p">}</span> <span class="n">Cake</span> <span class="o">*</span> <span class="nf">baker_bake_cake_sync</span> <span class="p">(</span><span class="n">Baker</span> <span class="o">*</span><span class="n">self</span><span class="p">,</span> <span class="n">guint</span> <span class="n">radius</span><span class="p">,</span> <span class="n">CakeFlavor</span> <span class="n">flavor</span><span class="p">,</span> <span class="n">CakeFrostingType</span> <span class="n">frosting</span><span class="p">,</span> <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">message</span><span class="p">,</span> <span class="n">GCancellable</span> <span class="o">*</span><span class="n">cancellable</span><span class="p">,</span> <span class="n">GError</span> <span class="o">**</span><span class="n">error</span><span class="p">)</span> <span class="p">{</span> <span class="n">CakeData</span> <span class="o">*</span><span class="n">cake_data</span><span class="p">;</span> <span class="n">GTask</span> <span class="o">*</span><span class="n">task</span><span class="p">;</span> <span class="n">Cake</span> <span class="o">*</span><span class="n">cake</span><span class="p">;</span> <span class="n">cake_data</span> <span class="o">=</span> <span class="n">g_slice_new</span> <span class="p">(</span><span class="n">CakeData</span><span class="p">);</span> <span class="p">...</span> <span class="n">task</span> <span class="o">=</span> <span class="n">g_task_new</span> <span class="p">(</span><span class="n">self</span><span class="p">,</span> <span class="n">cancellable</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span> <span class="n">g_task_set_task_data</span> <span class="p">(</span><span class="n">task</span><span class="p">,</span> <span class="n">cake_data</span><span class="p">,</span> <span class="p">(</span><span class="n">GDestroyNotify</span><span class="p">)</span> <span class="n">cake_data_free</span><span class="p">);</span> <span class="n">g_task_set_return_on_cancel</span> <span class="p">(</span><span class="n">task</span><span class="p">,</span> <span class="n">TRUE</span><span class="p">);</span> <span class="n">g_task_run_in_thread_sync</span> <span class="p">(</span><span class="n">task</span><span class="p">,</span> <span class="n">bake_cake_thread</span><span class="p">);</span> <span class="n">cake</span> <span class="o">=</span> <span class="n">g_task_propagate_pointer</span> <span class="p">(</span><span class="n">task</span><span class="p">,</span> <span class="n">error</span><span class="p">);</span> <span class="n">g_object_unref</span> <span class="p">(</span><span class="n">task</span><span class="p">);</span> <span class="k">return</span> <span class="n">cake</span><span class="p">;</span> <span class="p">}</span></pre></td> </tr> </tbody> </table> </div> <p></p> </div> <div class="refsect3"> <a name="id-1.4.5.4.9.7"></a><h4>Porting from GSimpleAsyncResult</h4> <p><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a>'s API attempts to be simpler than <a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult"><span class="type">GSimpleAsyncResult</span></a>'s in several ways:</p> <div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> <li class="listitem"><p>You can save task-specific data with <a class="link" href="GTask.html#g-task-set-task-data" title="g_task_set_task_data ()"><code class="function">g_task_set_task_data()</code></a>, and retrieve it later with <a class="link" href="GTask.html#g-task-get-task-data" title="g_task_get_task_data ()"><code class="function">g_task_get_task_data()</code></a>. This replaces the abuse of <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-set-op-res-gpointer" title="g_simple_async_result_set_op_res_gpointer ()"><code class="function">g_simple_async_result_set_op_res_gpointer()</code></a> for the same purpose with <a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult"><span class="type">GSimpleAsyncResult</span></a>.</p></li> <li class="listitem"><p>In addition to the task data, <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> also keeps track of the <a class="link" href="GAsyncResult.html#io-priority" title="I/O Priority">priority</a>, <a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a>, and <span class="type">GMainContext</span> associated with the task, so tasks that consist of a chain of simpler asynchronous operations will have easy access to those values when starting each sub-task.</p></li> <li class="listitem"><p>g_task_return_error_if_cancelled() provides simplified handling for cancellation. In addition, cancellation overrides any other <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> return value by default, like <a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult"><span class="type">GSimpleAsyncResult</span></a> does when <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-set-check-cancellable" title="g_simple_async_result_set_check_cancellable ()"><code class="function">g_simple_async_result_set_check_cancellable()</code></a> is called. (You can use <a class="link" href="GTask.html#g-task-set-check-cancellable" title="g_task_set_check_cancellable ()"><code class="function">g_task_set_check_cancellable()</code></a> to turn off that behavior.) On the other hand, <a class="link" href="GTask.html#g-task-run-in-thread" title="g_task_run_in_thread ()"><code class="function">g_task_run_in_thread()</code></a> guarantees that it will always run your <code class="literal">task_func</code>, even if the task's <a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a> is already cancelled before the task gets a chance to run; you can start your <code class="literal">task_func</code> with a <a class="link" href="GTask.html#g-task-return-error-if-cancelled" title="g_task_return_error_if_cancelled ()"><code class="function">g_task_return_error_if_cancelled()</code></a> check if you need the old behavior.</p></li> <li class="listitem"><p>The "return" methods (eg, <a class="link" href="GTask.html#g-task-return-pointer" title="g_task_return_pointer ()"><code class="function">g_task_return_pointer()</code></a>) automatically cause the task to be "completed" as well, and there is no need to worry about the "complete" vs "complete in idle" distinction. (<a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> automatically figures out whether the task's callback can be invoked directly, or if it needs to be sent to another <span class="type">GMainContext</span>, or delayed until the next iteration of the current <span class="type">GMainContext</span>.)</p></li> <li class="listitem"><p>The "finish" functions for <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> based operations are generally much simpler than <a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult"><span class="type">GSimpleAsyncResult</span></a> ones, normally consisting of only a single call to <a class="link" href="GTask.html#g-task-propagate-pointer" title="g_task_propagate_pointer ()"><code class="function">g_task_propagate_pointer()</code></a> or the like. Since <a class="link" href="GTask.html#g-task-propagate-pointer" title="g_task_propagate_pointer ()"><code class="function">g_task_propagate_pointer()</code></a> "steals" the return value from the <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a>, it is not necessary to juggle pointers around to prevent it from being freed twice.</p></li> <li class="listitem"><p>With <a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult"><span class="type">GSimpleAsyncResult</span></a>, it was common to call <a class="link" href="GSimpleAsyncResult.html#g-simple-async-result-propagate-error" title="g_simple_async_result_propagate_error ()"><code class="function">g_simple_async_result_propagate_error()</code></a> from the <code class="literal"><code class="function">_finish()</code></code> wrapper function, and have virtual method implementations only deal with successful returns. This behavior is deprecated, because it makes it difficult for a subclass to chain to a parent class's async methods. Instead, the wrapper function should just be a simple wrapper, and the virtual method should call an appropriate <code class="literal">g_task_propagate_</code> function. Note that wrapper methods can now use <a class="link" href="GAsyncResult.html#g-async-result-legacy-propagate-error" title="g_async_result_legacy_propagate_error ()"><code class="function">g_async_result_legacy_propagate_error()</code></a> to do old-style <a class="link" href="GSimpleAsyncResult.html" title="GSimpleAsyncResult"><span class="type">GSimpleAsyncResult</span></a> error-returning behavior, and <a class="link" href="GAsyncResult.html#g-async-result-is-tagged" title="g_async_result_is_tagged ()"><code class="function">g_async_result_is_tagged()</code></a> to check if a result is tagged as having come from the <code class="literal"><a class="link" href="async.html" title="Asynchronous I/O"><code class="function">_async()</code></a></code> wrapper function (for "short-circuit" results, such as when passing 0 to <a class="link" href="GInputStream.html#g-input-stream-read-async" title="g_input_stream_read_async ()"><code class="function">g_input_stream_read_async()</code></a>).</p></li> </ul></div> </div> </div> <div class="refsect1"> <a name="GTask.functions_details"></a><h2>Functions</h2> <div class="refsect2"> <a name="g-task-new"></a><h3>g_task_new ()</h3> <pre class="programlisting"><a class="link" href="GTask.html" title="GTask"><span class="returnvalue">GTask</span></a> * g_task_new (<em class="parameter"><code><span class="type">gpointer</span> source_object</code></em>, <em class="parameter"><code><a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a> *cancellable</code></em>, <em class="parameter"><code><a class="link" href="GAsyncResult.html#GAsyncReadyCallback" title="GAsyncReadyCallback ()"><span class="type">GAsyncReadyCallback</span></a> callback</code></em>, <em class="parameter"><code><span class="type">gpointer</span> callback_data</code></em>);</pre> <p>Creates a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> acting on <em class="parameter"><code>source_object</code></em> , which will eventually be used to invoke <em class="parameter"><code>callback</code></em> in the current thread-default main context.</p> <p>Call this in the "start" method of your asynchronous method, and pass the <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> around throughout the asynchronous operation. You can use <a class="link" href="GTask.html#g-task-set-task-data" title="g_task_set_task_data ()"><code class="function">g_task_set_task_data()</code></a> to attach task-specific data to the object, which you can retrieve later via <a class="link" href="GTask.html#g-task-get-task-data" title="g_task_get_task_data ()"><code class="function">g_task_get_task_data()</code></a>.</p> <p>By default, if <em class="parameter"><code>cancellable</code></em> is cancelled, then the return value of the task will always be <a class="link" href="gio-GIOError.html#G-IO-ERROR-CANCELLED:CAPS"><code class="literal">G_IO_ERROR_CANCELLED</code></a>, 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 <a class="link" href="GTask.html#g-task-set-check-cancellable" title="g_task_set_check_cancellable ()"><code class="function">g_task_set_check_cancellable()</code></a> to change it.</p> <div class="refsect3"> <a name="g-task-new.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody> <tr> <td class="parameter_name"><p>source_object</p></td> <td class="parameter_description"><p>the <span class="type">GObject</span> that owns this task, or <code class="literal">NULL</code>. </p></td> <td class="parameter_annotations"><span class="annotation">[<acronym title="NULL may be passed as the value in, out, in-out; or as a return value."><span class="acronym">nullable</span></acronym>][<acronym title="Override the parsed C type with given type."><span class="acronym">type</span></acronym> GObject]</span></td> </tr> <tr> <td class="parameter_name"><p>cancellable</p></td> <td class="parameter_description"><p>optional <a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a> object, <code class="literal">NULL</code> to ignore. </p></td> <td class="parameter_annotations"><span class="annotation">[<acronym title="NULL may be passed as the value in, out, in-out; or as a return value."><span class="acronym">nullable</span></acronym>]</span></td> </tr> <tr> <td class="parameter_name"><p>callback</p></td> <td class="parameter_description"><p>a <a class="link" href="GAsyncResult.html#GAsyncReadyCallback" title="GAsyncReadyCallback ()"><span class="type">GAsyncReadyCallback</span></a>. </p></td> <td class="parameter_annotations"><span class="annotation">[<acronym title="The callback is valid until first called."><span class="acronym">scope async</span></acronym>]</span></td> </tr> <tr> <td class="parameter_name"><p>callback_data</p></td> <td class="parameter_description"><p>user data passed to <em class="parameter"><code>callback</code></em> . </p></td> <td class="parameter_annotations"><span class="annotation">[<acronym title="This parameter is a 'user_data', for callbacks; many bindings can pass NULL here."><span class="acronym">closure</span></acronym>]</span></td> </tr> </tbody> </table></div> </div> <div class="refsect3"> <a name="g-task-new.returns"></a><h4>Returns</h4> <p> a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a>.</p> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-set-task-data"></a><h3>g_task_set_task_data ()</h3> <pre class="programlisting"><span class="returnvalue">void</span> g_task_set_task_data (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>, <em class="parameter"><code><span class="type">gpointer</span> task_data</code></em>, <em class="parameter"><code><span class="type">GDestroyNotify</span> task_data_destroy</code></em>);</pre> <p>Sets <em class="parameter"><code>task</code></em> 's task data (freeing the existing task data, if any).</p> <div class="refsect3"> <a name="g-task-set-task-data.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody> <tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>the <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a></p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>task_data</p></td> <td class="parameter_description"><p>task-specific data. </p></td> <td class="parameter_annotations"><span class="annotation">[<acronym title="NULL may be passed as the value in, out, in-out; or as a return value."><span class="acronym">nullable</span></acronym>]</span></td> </tr> <tr> <td class="parameter_name"><p>task_data_destroy</p></td> <td class="parameter_description"><p><span class="type">GDestroyNotify</span> for <em class="parameter"><code>task_data</code></em> . </p></td> <td class="parameter_annotations"><span class="annotation">[<acronym title="NULL may be passed as the value in, out, in-out; or as a return value."><span class="acronym">nullable</span></acronym>]</span></td> </tr> </tbody> </table></div> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-set-priority"></a><h3>g_task_set_priority ()</h3> <pre class="programlisting"><span class="returnvalue">void</span> g_task_set_priority (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>, <em class="parameter"><code><span class="type">gint</span> priority</code></em>);</pre> <p>Sets <em class="parameter"><code>task</code></em> 's priority. If you do not call this, it will default to <code class="literal">G_PRIORITY_DEFAULT</code>.</p> <p>This will affect the priority of <span class="type">GSources</span> created with <a class="link" href="GTask.html#g-task-attach-source" title="g_task_attach_source ()"><code class="function">g_task_attach_source()</code></a> and the scheduling of tasks run in threads, and can also be explicitly retrieved later via <a class="link" href="GTask.html#g-task-get-priority" title="g_task_get_priority ()"><code class="function">g_task_get_priority()</code></a>.</p> <div class="refsect3"> <a name="g-task-set-priority.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody> <tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>the <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a></p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>priority</p></td> <td class="parameter_description"><p>the <a class="link" href="GAsyncResult.html#io-priority" title="I/O Priority">priority</a> of the request</p></td> <td class="parameter_annotations"> </td> </tr> </tbody> </table></div> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-set-check-cancellable"></a><h3>g_task_set_check_cancellable ()</h3> <pre class="programlisting"><span class="returnvalue">void</span> g_task_set_check_cancellable (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>, <em class="parameter"><code><span class="type">gboolean</span> check_cancellable</code></em>);</pre> <p>Sets or clears <em class="parameter"><code>task</code></em> 's check-cancellable flag. If this is <code class="literal">TRUE</code> (the default), then <a class="link" href="GTask.html#g-task-propagate-pointer" title="g_task_propagate_pointer ()"><code class="function">g_task_propagate_pointer()</code></a>, etc, and <a class="link" href="GTask.html#g-task-had-error" title="g_task_had_error ()"><code class="function">g_task_had_error()</code></a> will check the task's <a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a> first, and if it has been cancelled, then they will consider the task to have returned an "Operation was cancelled" error (<a class="link" href="gio-GIOError.html#G-IO-ERROR-CANCELLED:CAPS"><code class="literal">G_IO_ERROR_CANCELLED</code></a>), regardless of any other error or return value the task may have had.</p> <p>If <em class="parameter"><code>check_cancellable</code></em> is <code class="literal">FALSE</code>, then the <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> will not check the cancellable itself, and it is up to <em class="parameter"><code>task</code></em> 's owner to do this (eg, via <a class="link" href="GTask.html#g-task-return-error-if-cancelled" title="g_task_return_error_if_cancelled ()"><code class="function">g_task_return_error_if_cancelled()</code></a>).</p> <p>If you are using <a class="link" href="GTask.html#g-task-set-return-on-cancel" title="g_task_set_return_on_cancel ()"><code class="function">g_task_set_return_on_cancel()</code></a> as well, then you must leave check-cancellable set <code class="literal">TRUE</code>.</p> <div class="refsect3"> <a name="g-task-set-check-cancellable.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody> <tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>the <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a></p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>check_cancellable</p></td> <td class="parameter_description"><p>whether <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> will check the state of its <a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a> for you.</p></td> <td class="parameter_annotations"> </td> </tr> </tbody> </table></div> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-set-return-on-cancel"></a><h3>g_task_set_return_on_cancel ()</h3> <pre class="programlisting"><span class="returnvalue">gboolean</span> g_task_set_return_on_cancel (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>, <em class="parameter"><code><span class="type">gboolean</span> return_on_cancel</code></em>);</pre> <p>Sets or clears <em class="parameter"><code>task</code></em> 's return-on-cancel flag. This is only meaningful for tasks run via <a class="link" href="GTask.html#g-task-run-in-thread" title="g_task_run_in_thread ()"><code class="function">g_task_run_in_thread()</code></a> or <a class="link" href="GTask.html#g-task-run-in-thread-sync" title="g_task_run_in_thread_sync ()"><code class="function">g_task_run_in_thread_sync()</code></a>.</p> <p>If <em class="parameter"><code>return_on_cancel</code></em> is <code class="literal">TRUE</code>, then cancelling <em class="parameter"><code>task</code></em> 's <a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a> will immediately cause it to return, as though the task's <a class="link" href="GTask.html#GTaskThreadFunc" title="GTaskThreadFunc ()"><span class="type">GTaskThreadFunc</span></a> had called <a class="link" href="GTask.html#g-task-return-error-if-cancelled" title="g_task_return_error_if_cancelled ()"><code class="function">g_task_return_error_if_cancelled()</code></a> and then returned.</p> <p>This allows you to create a cancellable wrapper around an uninterruptable function. The <a class="link" href="GTask.html#GTaskThreadFunc" title="GTaskThreadFunc ()"><span class="type">GTaskThreadFunc</span></a> 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 <a class="link" href="GTask.html#g-task-set-return-on-cancel" title="g_task_set_return_on_cancel ()"><code class="function">g_task_set_return_on_cancel()</code></a> again to (atomically) set return-on-cancel <code class="literal">FALSE</code> before making externally-visible changes; if the task gets cancelled before the return-on-cancel flag could be changed, <a class="link" href="GTask.html#g-task-set-return-on-cancel" title="g_task_set_return_on_cancel ()"><code class="function">g_task_set_return_on_cancel()</code></a> will indicate this by returning <code class="literal">FALSE</code>.</p> <p>You can disable and re-enable this flag multiple times if you wish. If the task's <a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a> is cancelled while return-on-cancel is <code class="literal">FALSE</code>, then calling <a class="link" href="GTask.html#g-task-set-return-on-cancel" title="g_task_set_return_on_cancel ()"><code class="function">g_task_set_return_on_cancel()</code></a> to set it <code class="literal">TRUE</code> again will cause the task to be cancelled at that point.</p> <p>If the task's <a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a> is already cancelled before you call <a class="link" href="GTask.html#g-task-run-in-thread" title="g_task_run_in_thread ()"><code class="function">g_task_run_in_thread()</code></a>/<a class="link" href="GTask.html#g-task-run-in-thread-sync" title="g_task_run_in_thread_sync ()"><code class="function">g_task_run_in_thread_sync()</code></a>, then the <a class="link" href="GTask.html#GTaskThreadFunc" title="GTaskThreadFunc ()"><span class="type">GTaskThreadFunc</span></a> will still be run (for consistency), but the task will also be completed right away.</p> <div class="refsect3"> <a name="g-task-set-return-on-cancel.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody> <tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>the <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a></p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>return_on_cancel</p></td> <td class="parameter_description"><p>whether the task returns automatically when it is cancelled.</p></td> <td class="parameter_annotations"> </td> </tr> </tbody> </table></div> </div> <div class="refsect3"> <a name="g-task-set-return-on-cancel.returns"></a><h4>Returns</h4> <p> <code class="literal">TRUE</code> if <em class="parameter"><code>task</code></em> 's return-on-cancel flag was changed to match <em class="parameter"><code>return_on_cancel</code></em> . <code class="literal">FALSE</code> if <em class="parameter"><code>task</code></em> has already been cancelled.</p> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-set-source-tag"></a><h3>g_task_set_source_tag ()</h3> <pre class="programlisting"><span class="returnvalue">void</span> g_task_set_source_tag (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>, <em class="parameter"><code><span class="type">gpointer</span> source_tag</code></em>);</pre> <p>Sets <em class="parameter"><code>task</code></em> 's source tag. You can use this to tag a task return value with a particular pointer (usually a pointer to the function doing the tagging) and then later check it using <a class="link" href="GTask.html#g-task-get-source-tag" title="g_task_get_source_tag ()"><code class="function">g_task_get_source_tag()</code></a> (or <a class="link" href="GAsyncResult.html#g-async-result-is-tagged" title="g_async_result_is_tagged ()"><code class="function">g_async_result_is_tagged()</code></a>) in the task's "finish" function, to figure out if the response came from a particular place.</p> <div class="refsect3"> <a name="g-task-set-source-tag.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody> <tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>the <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a></p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>source_tag</p></td> <td class="parameter_description"><p>an opaque pointer indicating the source of this task</p></td> <td class="parameter_annotations"> </td> </tr> </tbody> </table></div> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-set-name"></a><h3>g_task_set_name ()</h3> <pre class="programlisting"><span class="returnvalue">void</span> g_task_set_name (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>, <em class="parameter"><code>const <span class="type">gchar</span> *name</code></em>);</pre> <p>Sets <em class="parameter"><code>task</code></em> ’s name, used in debugging and profiling. The name defaults to <code class="literal">NULL</code>.</p> <p>The task name should describe in a human readable way what the task does. For example, ‘Open file’ or ‘Connect to network host’. It is used to set the name of the <span class="type">GSource</span> used for idle completion of the task.</p> <p>This function may only be called before the <em class="parameter"><code>task</code></em> is first used in a thread other than the one it was constructed in.</p> <div class="refsect3"> <a name="g-task-set-name.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody> <tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a></p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>name</p></td> <td class="parameter_description"><p>a human readable name for the task, or <code class="literal">NULL</code> to unset it. </p></td> <td class="parameter_annotations"><span class="annotation">[<acronym title="NULL may be passed as the value in, out, in-out; or as a return value."><span class="acronym">nullable</span></acronym>]</span></td> </tr> </tbody> </table></div> </div> <p class="since">Since: <a class="link" href="api-index-2-60.html#api-index-2.60">2.60</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-report-error"></a><h3>g_task_report_error ()</h3> <pre class="programlisting"><span class="returnvalue">void</span> g_task_report_error (<em class="parameter"><code><span class="type">gpointer</span> source_object</code></em>, <em class="parameter"><code><a class="link" href="GAsyncResult.html#GAsyncReadyCallback" title="GAsyncReadyCallback ()"><span class="type">GAsyncReadyCallback</span></a> callback</code></em>, <em class="parameter"><code><span class="type">gpointer</span> callback_data</code></em>, <em class="parameter"><code><span class="type">gpointer</span> source_tag</code></em>, <em class="parameter"><code><span class="type">GError</span> *error</code></em>);</pre> <p>Creates a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> and then immediately calls <a class="link" href="GTask.html#g-task-return-error" title="g_task_return_error ()"><code class="function">g_task_return_error()</code></a> on it. Use this in the wrapper function of an asynchronous method when you want to avoid even calling the virtual method. You can then use <a class="link" href="GAsyncResult.html#g-async-result-is-tagged" title="g_async_result_is_tagged ()"><code class="function">g_async_result_is_tagged()</code></a> in the finish method wrapper to check if the result there is tagged as having been created by the wrapper method, and deal with it appropriately if so.</p> <p>See also <a class="link" href="GTask.html#g-task-report-new-error" title="g_task_report_new_error ()"><code class="function">g_task_report_new_error()</code></a>.</p> <div class="refsect3"> <a name="g-task-report-error.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody> <tr> <td class="parameter_name"><p>source_object</p></td> <td class="parameter_description"><p>the <span class="type">GObject</span> that owns this task, or <code class="literal">NULL</code>. </p></td> <td class="parameter_annotations"><span class="annotation">[<acronym title="NULL may be passed as the value in, out, in-out; or as a return value."><span class="acronym">nullable</span></acronym>][<acronym title="Override the parsed C type with given type."><span class="acronym">type</span></acronym> GObject]</span></td> </tr> <tr> <td class="parameter_name"><p>callback</p></td> <td class="parameter_description"><p>a <a class="link" href="GAsyncResult.html#GAsyncReadyCallback" title="GAsyncReadyCallback ()"><span class="type">GAsyncReadyCallback</span></a>. </p></td> <td class="parameter_annotations"><span class="annotation">[<acronym title="The callback is valid until first called."><span class="acronym">scope async</span></acronym>]</span></td> </tr> <tr> <td class="parameter_name"><p>callback_data</p></td> <td class="parameter_description"><p>user data passed to <em class="parameter"><code>callback</code></em> . </p></td> <td class="parameter_annotations"><span class="annotation">[<acronym title="This parameter is a 'user_data', for callbacks; many bindings can pass NULL here."><span class="acronym">closure</span></acronym>]</span></td> </tr> <tr> <td class="parameter_name"><p>source_tag</p></td> <td class="parameter_description"><p>an opaque pointer indicating the source of this task</p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>error</p></td> <td class="parameter_description"><p>error to report. </p></td> <td class="parameter_annotations"><span class="annotation">[<acronym title="Free data after the code is done."><span class="acronym">transfer full</span></acronym>]</span></td> </tr> </tbody> </table></div> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-report-new-error"></a><h3>g_task_report_new_error ()</h3> <pre class="programlisting"><span class="returnvalue">void</span> g_task_report_new_error (<em class="parameter"><code><span class="type">gpointer</span> source_object</code></em>, <em class="parameter"><code><a class="link" href="GAsyncResult.html#GAsyncReadyCallback" title="GAsyncReadyCallback ()"><span class="type">GAsyncReadyCallback</span></a> callback</code></em>, <em class="parameter"><code><span class="type">gpointer</span> callback_data</code></em>, <em class="parameter"><code><span class="type">gpointer</span> source_tag</code></em>, <em class="parameter"><code><span class="type">GQuark</span> domain</code></em>, <em class="parameter"><code><span class="type">gint</span> code</code></em>, <em class="parameter"><code>const <span class="type">char</span> *format</code></em>, <em class="parameter"><code>...</code></em>);</pre> <p>Creates a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> and then immediately calls <a class="link" href="GTask.html#g-task-return-new-error" title="g_task_return_new_error ()"><code class="function">g_task_return_new_error()</code></a> on it. Use this in the wrapper function of an asynchronous method when you want to avoid even calling the virtual method. You can then use <a class="link" href="GAsyncResult.html#g-async-result-is-tagged" title="g_async_result_is_tagged ()"><code class="function">g_async_result_is_tagged()</code></a> in the finish method wrapper to check if the result there is tagged as having been created by the wrapper method, and deal with it appropriately if so.</p> <p>See also <a class="link" href="GTask.html#g-task-report-error" title="g_task_report_error ()"><code class="function">g_task_report_error()</code></a>.</p> <div class="refsect3"> <a name="g-task-report-new-error.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody> <tr> <td class="parameter_name"><p>source_object</p></td> <td class="parameter_description"><p>the <span class="type">GObject</span> that owns this task, or <code class="literal">NULL</code>. </p></td> <td class="parameter_annotations"><span class="annotation">[<acronym title="NULL may be passed as the value in, out, in-out; or as a return value."><span class="acronym">nullable</span></acronym>][<acronym title="Override the parsed C type with given type."><span class="acronym">type</span></acronym> GObject]</span></td> </tr> <tr> <td class="parameter_name"><p>callback</p></td> <td class="parameter_description"><p>a <a class="link" href="GAsyncResult.html#GAsyncReadyCallback" title="GAsyncReadyCallback ()"><span class="type">GAsyncReadyCallback</span></a>. </p></td> <td class="parameter_annotations"><span class="annotation">[<acronym title="The callback is valid until first called."><span class="acronym">scope async</span></acronym>]</span></td> </tr> <tr> <td class="parameter_name"><p>callback_data</p></td> <td class="parameter_description"><p>user data passed to <em class="parameter"><code>callback</code></em> . </p></td> <td class="parameter_annotations"><span class="annotation">[<acronym title="This parameter is a 'user_data', for callbacks; many bindings can pass NULL here."><span class="acronym">closure</span></acronym>]</span></td> </tr> <tr> <td class="parameter_name"><p>source_tag</p></td> <td class="parameter_description"><p>an opaque pointer indicating the source of this task</p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>domain</p></td> <td class="parameter_description"><p>a <span class="type">GQuark</span>.</p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>code</p></td> <td class="parameter_description"><p>an error code.</p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>format</p></td> <td class="parameter_description"><p>a string with format characters.</p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>...</p></td> <td class="parameter_description"><p>a list of values to insert into <em class="parameter"><code>format</code></em> .</p></td> <td class="parameter_annotations"> </td> </tr> </tbody> </table></div> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-get-task-data"></a><h3>g_task_get_task_data ()</h3> <pre class="programlisting"><span class="returnvalue">gpointer</span> g_task_get_task_data (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>);</pre> <p>Gets <em class="parameter"><code>task</code></em> 's <code class="literal">task_data</code>.</p> <div class="refsect3"> <a name="g-task-get-task-data.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody><tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a></p></td> <td class="parameter_annotations"> </td> </tr></tbody> </table></div> </div> <div class="refsect3"> <a name="g-task-get-task-data.returns"></a><h4>Returns</h4> <p><em class="parameter"><code>task</code></em> 's <code class="literal">task_data</code>. </p> <p><span class="annotation">[<acronym title="Don't free data after the code is done."><span class="acronym">transfer none</span></acronym>]</span></p> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-get-priority"></a><h3>g_task_get_priority ()</h3> <pre class="programlisting"><span class="returnvalue">gint</span> g_task_get_priority (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>);</pre> <p>Gets <em class="parameter"><code>task</code></em> 's priority</p> <div class="refsect3"> <a name="g-task-get-priority.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody><tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a></p></td> <td class="parameter_annotations"> </td> </tr></tbody> </table></div> </div> <div class="refsect3"> <a name="g-task-get-priority.returns"></a><h4>Returns</h4> <p> <em class="parameter"><code>task</code></em> 's priority</p> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-get-cancellable"></a><h3>g_task_get_cancellable ()</h3> <pre class="programlisting"><a class="link" href="GCancellable.html" title="GCancellable"><span class="returnvalue">GCancellable</span></a> * g_task_get_cancellable (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>);</pre> <p>Gets <em class="parameter"><code>task</code></em> 's <a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a></p> <div class="refsect3"> <a name="g-task-get-cancellable.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody><tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a></p></td> <td class="parameter_annotations"> </td> </tr></tbody> </table></div> </div> <div class="refsect3"> <a name="g-task-get-cancellable.returns"></a><h4>Returns</h4> <p><em class="parameter"><code>task</code></em> 's <a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a>. </p> <p><span class="annotation">[<acronym title="Don't free data after the code is done."><span class="acronym">transfer none</span></acronym>]</span></p> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-get-check-cancellable"></a><h3>g_task_get_check_cancellable ()</h3> <pre class="programlisting"><span class="returnvalue">gboolean</span> g_task_get_check_cancellable (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>);</pre> <p>Gets <em class="parameter"><code>task</code></em> 's check-cancellable flag. See <a class="link" href="GTask.html#g-task-set-check-cancellable" title="g_task_set_check_cancellable ()"><code class="function">g_task_set_check_cancellable()</code></a> for more details.</p> <div class="refsect3"> <a name="g-task-get-check-cancellable.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody><tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>the <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a></p></td> <td class="parameter_annotations"> </td> </tr></tbody> </table></div> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-get-return-on-cancel"></a><h3>g_task_get_return_on_cancel ()</h3> <pre class="programlisting"><span class="returnvalue">gboolean</span> g_task_get_return_on_cancel (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>);</pre> <p>Gets <em class="parameter"><code>task</code></em> 's return-on-cancel flag. See <a class="link" href="GTask.html#g-task-set-return-on-cancel" title="g_task_set_return_on_cancel ()"><code class="function">g_task_set_return_on_cancel()</code></a> for more details.</p> <div class="refsect3"> <a name="g-task-get-return-on-cancel.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody><tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>the <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a></p></td> <td class="parameter_annotations"> </td> </tr></tbody> </table></div> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-get-context"></a><h3>g_task_get_context ()</h3> <pre class="programlisting"><span class="returnvalue">GMainContext</span> * g_task_get_context (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>);</pre> <p>Gets the <span class="type">GMainContext</span> that <em class="parameter"><code>task</code></em> will return its result in (that is, the context that was the thread-default main context at the point when <em class="parameter"><code>task</code></em> was created).</p> <p>This will always return a non-<code class="literal">NULL</code> value, even if the task's context is the default <span class="type">GMainContext</span>.</p> <div class="refsect3"> <a name="g-task-get-context.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody><tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a></p></td> <td class="parameter_annotations"> </td> </tr></tbody> </table></div> </div> <div class="refsect3"> <a name="g-task-get-context.returns"></a><h4>Returns</h4> <p><em class="parameter"><code>task</code></em> 's <span class="type">GMainContext</span>. </p> <p><span class="annotation">[<acronym title="Don't free data after the code is done."><span class="acronym">transfer none</span></acronym>]</span></p> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-get-source-object"></a><h3>g_task_get_source_object ()</h3> <pre class="programlisting"><span class="returnvalue">gpointer</span> g_task_get_source_object (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>);</pre> <p>Gets the source object from <em class="parameter"><code>task</code></em> . Like <a class="link" href="GAsyncResult.html#g-async-result-get-source-object" title="g_async_result_get_source_object ()"><code class="function">g_async_result_get_source_object()</code></a>, but does not ref the object.</p> <div class="refsect3"> <a name="g-task-get-source-object.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody><tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a></p></td> <td class="parameter_annotations"> </td> </tr></tbody> </table></div> </div> <div class="refsect3"> <a name="g-task-get-source-object.returns"></a><h4>Returns</h4> <p><em class="parameter"><code>task</code></em> 's source object, or <code class="literal">NULL</code>. </p> <p><span class="annotation">[<acronym title="Don't free data after the code is done."><span class="acronym">transfer none</span></acronym>][<acronym title="NULL may be passed as the value in, out, in-out; or as a return value."><span class="acronym">nullable</span></acronym>][<acronym title="Override the parsed C type with given type."><span class="acronym">type</span></acronym> GObject]</span></p> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-get-source-tag"></a><h3>g_task_get_source_tag ()</h3> <pre class="programlisting"><span class="returnvalue">gpointer</span> g_task_get_source_tag (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>);</pre> <p>Gets <em class="parameter"><code>task</code></em> 's source tag. See <a class="link" href="GTask.html#g-task-set-source-tag" title="g_task_set_source_tag ()"><code class="function">g_task_set_source_tag()</code></a>.</p> <div class="refsect3"> <a name="g-task-get-source-tag.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody><tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a></p></td> <td class="parameter_annotations"> </td> </tr></tbody> </table></div> </div> <div class="refsect3"> <a name="g-task-get-source-tag.returns"></a><h4>Returns</h4> <p><em class="parameter"><code>task</code></em> 's source tag. </p> <p><span class="annotation">[<acronym title="Don't free data after the code is done."><span class="acronym">transfer none</span></acronym>]</span></p> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-get-name"></a><h3>g_task_get_name ()</h3> <pre class="programlisting">const <span class="returnvalue">gchar</span> * g_task_get_name (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>);</pre> <p>Gets <em class="parameter"><code>task</code></em> ’s name. See <a class="link" href="GTask.html#g-task-set-name" title="g_task_set_name ()"><code class="function">g_task_set_name()</code></a>.</p> <div class="refsect3"> <a name="g-task-get-name.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody><tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a></p></td> <td class="parameter_annotations"> </td> </tr></tbody> </table></div> </div> <div class="refsect3"> <a name="g-task-get-name.returns"></a><h4>Returns</h4> <p><em class="parameter"><code>task</code></em> ’s name, or <code class="literal">NULL</code>. </p> <p><span class="annotation">[<acronym title="NULL may be passed as the value in, out, in-out; or as a return value."><span class="acronym">nullable</span></acronym>][<acronym title="Don't free data after the code is done."><span class="acronym">transfer none</span></acronym>]</span></p> </div> <p class="since">Since: <a class="link" href="api-index-2-60.html#api-index-2.60">2.60</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-return-boolean"></a><h3>g_task_return_boolean ()</h3> <pre class="programlisting"><span class="returnvalue">void</span> g_task_return_boolean (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>, <em class="parameter"><code><span class="type">gboolean</span> result</code></em>);</pre> <p>Sets <em class="parameter"><code>task</code></em> 's result to <em class="parameter"><code>result</code></em> and completes the task (see <a class="link" href="GTask.html#g-task-return-pointer" title="g_task_return_pointer ()"><code class="function">g_task_return_pointer()</code></a> for more discussion of exactly what this means).</p> <div class="refsect3"> <a name="g-task-return-boolean.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody> <tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a>.</p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>result</p></td> <td class="parameter_description"><p>the <span class="type">gboolean</span> result of a task function.</p></td> <td class="parameter_annotations"> </td> </tr> </tbody> </table></div> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-return-int"></a><h3>g_task_return_int ()</h3> <pre class="programlisting"><span class="returnvalue">void</span> g_task_return_int (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>, <em class="parameter"><code><span class="type">gssize</span> result</code></em>);</pre> <p>Sets <em class="parameter"><code>task</code></em> 's result to <em class="parameter"><code>result</code></em> and completes the task (see <a class="link" href="GTask.html#g-task-return-pointer" title="g_task_return_pointer ()"><code class="function">g_task_return_pointer()</code></a> for more discussion of exactly what this means).</p> <div class="refsect3"> <a name="g-task-return-int.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody> <tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a>.</p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>result</p></td> <td class="parameter_description"><p>the integer (<span class="type">gssize</span>) result of a task function.</p></td> <td class="parameter_annotations"> </td> </tr> </tbody> </table></div> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-return-pointer"></a><h3>g_task_return_pointer ()</h3> <pre class="programlisting"><span class="returnvalue">void</span> g_task_return_pointer (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>, <em class="parameter"><code><span class="type">gpointer</span> result</code></em>, <em class="parameter"><code><span class="type">GDestroyNotify</span> result_destroy</code></em>);</pre> <p>Sets <em class="parameter"><code>task</code></em> 's result to <em class="parameter"><code>result</code></em> and completes the task. If <em class="parameter"><code>result</code></em> is not <code class="literal">NULL</code>, then <em class="parameter"><code>result_destroy</code></em> will be used to free <em class="parameter"><code>result</code></em> if the caller does not take ownership of it with <a class="link" href="GTask.html#g-task-propagate-pointer" title="g_task_propagate_pointer ()"><code class="function">g_task_propagate_pointer()</code></a>.</p> <p>"Completes the task" means that for an ordinary asynchronous task it will either invoke the task's callback, or else queue that callback to be invoked in the proper <span class="type">GMainContext</span>, or in the next iteration of the current <span class="type">GMainContext</span>. For a task run via <a class="link" href="GTask.html#g-task-run-in-thread" title="g_task_run_in_thread ()"><code class="function">g_task_run_in_thread()</code></a> or <a class="link" href="GTask.html#g-task-run-in-thread-sync" title="g_task_run_in_thread_sync ()"><code class="function">g_task_run_in_thread_sync()</code></a>, calling this method will save <em class="parameter"><code>result</code></em> to be returned to the caller later, but the task will not actually be completed until the <a class="link" href="GTask.html#GTaskThreadFunc" title="GTaskThreadFunc ()"><span class="type">GTaskThreadFunc</span></a> exits.</p> <p>Note that since the task may be completed before returning from <a class="link" href="GTask.html#g-task-return-pointer" title="g_task_return_pointer ()"><code class="function">g_task_return_pointer()</code></a>, you cannot assume that <em class="parameter"><code>result</code></em> is still valid after calling this, unless you are still holding another reference on it.</p> <div class="refsect3"> <a name="g-task-return-pointer.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody> <tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a></p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>result</p></td> <td class="parameter_description"><p>the pointer result of a task function. </p></td> <td class="parameter_annotations"><span class="annotation">[<acronym title="NULL may be passed as the value in, out, in-out; or as a return value."><span class="acronym">nullable</span></acronym>][<acronym title="Free data after the code is done."><span class="acronym">transfer full</span></acronym>]</span></td> </tr> <tr> <td class="parameter_name"><p>result_destroy</p></td> <td class="parameter_description"><p>a <span class="type">GDestroyNotify</span> function. </p></td> <td class="parameter_annotations"><span class="annotation">[<acronym title="NULL may be passed as the value in, out, in-out; or as a return value."><span class="acronym">nullable</span></acronym>]</span></td> </tr> </tbody> </table></div> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-return-value"></a><h3>g_task_return_value ()</h3> <pre class="programlisting"><span class="returnvalue">void</span> g_task_return_value (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>, <em class="parameter"><code><span class="type">GValue</span> *result</code></em>);</pre> <p>Sets <em class="parameter"><code>task</code></em> 's result to <em class="parameter"><code>result</code></em> (by copying it) and completes the task.</p> <p>If <em class="parameter"><code>result</code></em> is <code class="literal">NULL</code> then a <span class="type">GValue</span> of type <span class="type">G_TYPE_POINTER</span> with a value of <code class="literal">NULL</code> will be used for the result.</p> <p>This is a very generic low-level method intended primarily for use by language bindings; for C code, <a class="link" href="GTask.html#g-task-return-pointer" title="g_task_return_pointer ()"><code class="function">g_task_return_pointer()</code></a> and the like will normally be much easier to use.</p> <div class="refsect3"> <a name="g-task-return-value.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody> <tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a></p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>result</p></td> <td class="parameter_description"><p>the <span class="type">GValue</span> result of a task function. </p></td> <td class="parameter_annotations"><span class="annotation">[<acronym title="NULL may be passed as the value in, out, in-out; or as a return value."><span class="acronym">nullable</span></acronym>][<acronym title="Don't free data after the code is done."><span class="acronym">transfer none</span></acronym>]</span></td> </tr> </tbody> </table></div> </div> <p class="since">Since: <a class="link" href="api-index-2-64.html#api-index-2.64">2.64</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-return-error"></a><h3>g_task_return_error ()</h3> <pre class="programlisting"><span class="returnvalue">void</span> g_task_return_error (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>, <em class="parameter"><code><span class="type">GError</span> *error</code></em>);</pre> <p>Sets <em class="parameter"><code>task</code></em> 's result to <em class="parameter"><code>error</code></em> (which <em class="parameter"><code>task</code></em> assumes ownership of) and completes the task (see <a class="link" href="GTask.html#g-task-return-pointer" title="g_task_return_pointer ()"><code class="function">g_task_return_pointer()</code></a> for more discussion of exactly what this means).</p> <p>Note that since the task takes ownership of <em class="parameter"><code>error</code></em> , and since the task may be completed before returning from <a class="link" href="GTask.html#g-task-return-error" title="g_task_return_error ()"><code class="function">g_task_return_error()</code></a>, you cannot assume that <em class="parameter"><code>error</code></em> is still valid after calling this. Call <code class="function">g_error_copy()</code> on the error if you need to keep a local copy as well.</p> <p>See also <a class="link" href="GTask.html#g-task-return-new-error" title="g_task_return_new_error ()"><code class="function">g_task_return_new_error()</code></a>.</p> <div class="refsect3"> <a name="g-task-return-error.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody> <tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a>.</p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>error</p></td> <td class="parameter_description"><p>the <span class="type">GError</span> result of a task function. </p></td> <td class="parameter_annotations"><span class="annotation">[<acronym title="Free data after the code is done."><span class="acronym">transfer full</span></acronym>]</span></td> </tr> </tbody> </table></div> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-return-new-error"></a><h3>g_task_return_new_error ()</h3> <pre class="programlisting"><span class="returnvalue">void</span> g_task_return_new_error (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>, <em class="parameter"><code><span class="type">GQuark</span> domain</code></em>, <em class="parameter"><code><span class="type">gint</span> code</code></em>, <em class="parameter"><code>const <span class="type">char</span> *format</code></em>, <em class="parameter"><code>...</code></em>);</pre> <p>Sets <em class="parameter"><code>task</code></em> 's result to a new <span class="type">GError</span> created from <em class="parameter"><code>domain</code></em> , <em class="parameter"><code>code</code></em> , <em class="parameter"><code>format</code></em> , and the remaining arguments, and completes the task (see <a class="link" href="GTask.html#g-task-return-pointer" title="g_task_return_pointer ()"><code class="function">g_task_return_pointer()</code></a> for more discussion of exactly what this means).</p> <p>See also <a class="link" href="GTask.html#g-task-return-error" title="g_task_return_error ()"><code class="function">g_task_return_error()</code></a>.</p> <div class="refsect3"> <a name="g-task-return-new-error.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody> <tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a>.</p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>domain</p></td> <td class="parameter_description"><p>a <span class="type">GQuark</span>.</p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>code</p></td> <td class="parameter_description"><p>an error code.</p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>format</p></td> <td class="parameter_description"><p>a string with format characters.</p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>...</p></td> <td class="parameter_description"><p>a list of values to insert into <em class="parameter"><code>format</code></em> .</p></td> <td class="parameter_annotations"> </td> </tr> </tbody> </table></div> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-return-error-if-cancelled"></a><h3>g_task_return_error_if_cancelled ()</h3> <pre class="programlisting"><span class="returnvalue">gboolean</span> g_task_return_error_if_cancelled (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>);</pre> <p>Checks if <em class="parameter"><code>task</code></em> 's <a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a> has been cancelled, and if so, sets <em class="parameter"><code>task</code></em> 's error accordingly and completes the task (see <a class="link" href="GTask.html#g-task-return-pointer" title="g_task_return_pointer ()"><code class="function">g_task_return_pointer()</code></a> for more discussion of exactly what this means).</p> <div class="refsect3"> <a name="g-task-return-error-if-cancelled.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody><tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a></p></td> <td class="parameter_annotations"> </td> </tr></tbody> </table></div> </div> <div class="refsect3"> <a name="g-task-return-error-if-cancelled.returns"></a><h4>Returns</h4> <p> <code class="literal">TRUE</code> if <em class="parameter"><code>task</code></em> has been cancelled, <code class="literal">FALSE</code> if not</p> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-propagate-boolean"></a><h3>g_task_propagate_boolean ()</h3> <pre class="programlisting"><span class="returnvalue">gboolean</span> g_task_propagate_boolean (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>, <em class="parameter"><code><span class="type">GError</span> **error</code></em>);</pre> <p>Gets the result of <em class="parameter"><code>task</code></em> as a <span class="type">gboolean</span>.</p> <p>If the task resulted in an error, or was cancelled, then this will instead return <code class="literal">FALSE</code> and set <em class="parameter"><code>error</code></em> .</p> <p>Since this method transfers ownership of the return value (or error) to the caller, you may only call it once.</p> <div class="refsect3"> <a name="g-task-propagate-boolean.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody> <tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a>.</p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>error</p></td> <td class="parameter_description"><p>return location for a <span class="type">GError</span></p></td> <td class="parameter_annotations"> </td> </tr> </tbody> </table></div> </div> <div class="refsect3"> <a name="g-task-propagate-boolean.returns"></a><h4>Returns</h4> <p> the task result, or <code class="literal">FALSE</code> on error</p> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-propagate-int"></a><h3>g_task_propagate_int ()</h3> <pre class="programlisting"><span class="returnvalue">gssize</span> g_task_propagate_int (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>, <em class="parameter"><code><span class="type">GError</span> **error</code></em>);</pre> <p>Gets the result of <em class="parameter"><code>task</code></em> as an integer (<span class="type">gssize</span>).</p> <p>If the task resulted in an error, or was cancelled, then this will instead return -1 and set <em class="parameter"><code>error</code></em> .</p> <p>Since this method transfers ownership of the return value (or error) to the caller, you may only call it once.</p> <div class="refsect3"> <a name="g-task-propagate-int.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody> <tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a>.</p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>error</p></td> <td class="parameter_description"><p>return location for a <span class="type">GError</span></p></td> <td class="parameter_annotations"> </td> </tr> </tbody> </table></div> </div> <div class="refsect3"> <a name="g-task-propagate-int.returns"></a><h4>Returns</h4> <p> the task result, or -1 on error</p> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-propagate-pointer"></a><h3>g_task_propagate_pointer ()</h3> <pre class="programlisting"><span class="returnvalue">gpointer</span> g_task_propagate_pointer (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>, <em class="parameter"><code><span class="type">GError</span> **error</code></em>);</pre> <p>Gets the result of <em class="parameter"><code>task</code></em> as a pointer, and transfers ownership of that value to the caller.</p> <p>If the task resulted in an error, or was cancelled, then this will instead return <code class="literal">NULL</code> and set <em class="parameter"><code>error</code></em> .</p> <p>Since this method transfers ownership of the return value (or error) to the caller, you may only call it once.</p> <div class="refsect3"> <a name="g-task-propagate-pointer.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody> <tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a></p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>error</p></td> <td class="parameter_description"><p>return location for a <span class="type">GError</span></p></td> <td class="parameter_annotations"> </td> </tr> </tbody> </table></div> </div> <div class="refsect3"> <a name="g-task-propagate-pointer.returns"></a><h4>Returns</h4> <p>the task result, or <code class="literal">NULL</code> on error. </p> <p><span class="annotation">[<acronym title="Free data after the code is done."><span class="acronym">transfer full</span></acronym>]</span></p> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-propagate-value"></a><h3>g_task_propagate_value ()</h3> <pre class="programlisting"><span class="returnvalue">gboolean</span> g_task_propagate_value (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>, <em class="parameter"><code><span class="type">GValue</span> *value</code></em>, <em class="parameter"><code><span class="type">GError</span> **error</code></em>);</pre> <p>Gets the result of <em class="parameter"><code>task</code></em> as a <span class="type">GValue</span>, and transfers ownership of that value to the caller. As with <a class="link" href="GTask.html#g-task-return-value" title="g_task_return_value ()"><code class="function">g_task_return_value()</code></a>, this is a generic low-level method; <a class="link" href="GTask.html#g-task-propagate-pointer" title="g_task_propagate_pointer ()"><code class="function">g_task_propagate_pointer()</code></a> and the like will usually be more useful for C code.</p> <p>If the task resulted in an error, or was cancelled, then this will instead set <em class="parameter"><code>error</code></em> and return <code class="literal">FALSE</code>.</p> <p>Since this method transfers ownership of the return value (or error) to the caller, you may only call it once.</p> <div class="refsect3"> <a name="g-task-propagate-value.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody> <tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a></p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>value</p></td> <td class="parameter_description"><p>return location for the <span class="type">GValue</span>. </p></td> <td class="parameter_annotations"><span class="annotation">[<acronym title="Out parameter, where caller must allocate storage."><span class="acronym">out caller-allocates</span></acronym>]</span></td> </tr> <tr> <td class="parameter_name"><p>error</p></td> <td class="parameter_description"><p>return location for a <span class="type">GError</span></p></td> <td class="parameter_annotations"> </td> </tr> </tbody> </table></div> </div> <div class="refsect3"> <a name="g-task-propagate-value.returns"></a><h4>Returns</h4> <p> <code class="literal">TRUE</code> if <em class="parameter"><code>task</code></em> succeeded, <code class="literal">FALSE</code> on error.</p> </div> <p class="since">Since: <a class="link" href="api-index-2-64.html#api-index-2.64">2.64</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-had-error"></a><h3>g_task_had_error ()</h3> <pre class="programlisting"><span class="returnvalue">gboolean</span> g_task_had_error (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>);</pre> <p>Tests if <em class="parameter"><code>task</code></em> resulted in an error.</p> <div class="refsect3"> <a name="g-task-had-error.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody><tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a>.</p></td> <td class="parameter_annotations"> </td> </tr></tbody> </table></div> </div> <div class="refsect3"> <a name="g-task-had-error.returns"></a><h4>Returns</h4> <p> <code class="literal">TRUE</code> if the task resulted in an error, <code class="literal">FALSE</code> otherwise.</p> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-get-completed"></a><h3>g_task_get_completed ()</h3> <pre class="programlisting"><span class="returnvalue">gboolean</span> g_task_get_completed (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>);</pre> <p>Gets the value of <a class="link" href="GTask.html#GTask--completed" title="The “completed” property"><span class="type">“completed”</span></a>. This changes from <code class="literal">FALSE</code> to <code class="literal">TRUE</code> after the task’s callback is invoked, and will return <code class="literal">FALSE</code> if called from inside the callback.</p> <div class="refsect3"> <a name="g-task-get-completed.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody><tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a>.</p></td> <td class="parameter_annotations"> </td> </tr></tbody> </table></div> </div> <div class="refsect3"> <a name="g-task-get-completed.returns"></a><h4>Returns</h4> <p> <code class="literal">TRUE</code> if the task has completed, <code class="literal">FALSE</code> otherwise.</p> </div> <p class="since">Since: <a class="link" href="api-index-2-44.html#api-index-2.44">2.44</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-run-in-thread"></a><h3>g_task_run_in_thread ()</h3> <pre class="programlisting"><span class="returnvalue">void</span> g_task_run_in_thread (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>, <em class="parameter"><code><a class="link" href="GTask.html#GTaskThreadFunc" title="GTaskThreadFunc ()"><span class="type">GTaskThreadFunc</span></a> task_func</code></em>);</pre> <p>Runs <em class="parameter"><code>task_func</code></em> in another thread. When <em class="parameter"><code>task_func</code></em> returns, <em class="parameter"><code>task</code></em> 's <a class="link" href="GAsyncResult.html#GAsyncReadyCallback" title="GAsyncReadyCallback ()"><span class="type">GAsyncReadyCallback</span></a> will be invoked in <em class="parameter"><code>task</code></em> 's <span class="type">GMainContext</span>.</p> <p>This takes a ref on <em class="parameter"><code>task</code></em> until the task completes.</p> <p>See <a class="link" href="GTask.html#GTaskThreadFunc" title="GTaskThreadFunc ()"><span class="type">GTaskThreadFunc</span></a> for more details about how <em class="parameter"><code>task_func</code></em> is handled.</p> <p>Although GLib currently rate-limits the tasks queued via <a class="link" href="GTask.html#g-task-run-in-thread" title="g_task_run_in_thread ()"><code class="function">g_task_run_in_thread()</code></a>, you should not assume that it will always do this. If you have a very large number of tasks to run, but don't want them to all run at once, you should only queue a limited number of them at a time.</p> <div class="refsect3"> <a name="g-task-run-in-thread.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody> <tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a></p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>task_func</p></td> <td class="parameter_description"><p>a <a class="link" href="GTask.html#GTaskThreadFunc" title="GTaskThreadFunc ()"><span class="type">GTaskThreadFunc</span></a>. </p></td> <td class="parameter_annotations"><span class="annotation">[<acronym title="The callback is valid until first called."><span class="acronym">scope async</span></acronym>]</span></td> </tr> </tbody> </table></div> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-run-in-thread-sync"></a><h3>g_task_run_in_thread_sync ()</h3> <pre class="programlisting"><span class="returnvalue">void</span> g_task_run_in_thread_sync (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>, <em class="parameter"><code><a class="link" href="GTask.html#GTaskThreadFunc" title="GTaskThreadFunc ()"><span class="type">GTaskThreadFunc</span></a> task_func</code></em>);</pre> <p>Runs <em class="parameter"><code>task_func</code></em> in another thread, and waits for it to return or be cancelled. You can use <a class="link" href="GTask.html#g-task-propagate-pointer" title="g_task_propagate_pointer ()"><code class="function">g_task_propagate_pointer()</code></a>, etc, afterward to get the result of <em class="parameter"><code>task_func</code></em> .</p> <p>See <a class="link" href="GTask.html#GTaskThreadFunc" title="GTaskThreadFunc ()"><span class="type">GTaskThreadFunc</span></a> for more details about how <em class="parameter"><code>task_func</code></em> is handled.</p> <p>Normally this is used with tasks created with a <code class="literal">NULL</code> <code class="literal">callback</code>, but note that even if the task does have a callback, it will not be invoked when <em class="parameter"><code>task_func</code></em> returns. <a class="link" href="GTask.html#GTask--completed" title="The “completed” property"><span class="type">“completed”</span></a> will be set to <code class="literal">TRUE</code> just before this function returns.</p> <p>Although GLib currently rate-limits the tasks queued via <a class="link" href="GTask.html#g-task-run-in-thread-sync" title="g_task_run_in_thread_sync ()"><code class="function">g_task_run_in_thread_sync()</code></a>, you should not assume that it will always do this. If you have a very large number of tasks to run, but don't want them to all run at once, you should only queue a limited number of them at a time.</p> <div class="refsect3"> <a name="g-task-run-in-thread-sync.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody> <tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a></p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>task_func</p></td> <td class="parameter_description"><p>a <a class="link" href="GTask.html#GTaskThreadFunc" title="GTaskThreadFunc ()"><span class="type">GTaskThreadFunc</span></a>. </p></td> <td class="parameter_annotations"><span class="annotation">[<acronym title="The callback is valid until first called."><span class="acronym">scope async</span></acronym>]</span></td> </tr> </tbody> </table></div> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="GTaskThreadFunc"></a><h3>GTaskThreadFunc ()</h3> <pre class="programlisting"><span class="returnvalue">void</span> <span class="c_punctuation">(</span>*GTaskThreadFunc<span class="c_punctuation">)</span> (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>, <em class="parameter"><code><span class="type">gpointer</span> source_object</code></em>, <em class="parameter"><code><span class="type">gpointer</span> task_data</code></em>, <em class="parameter"><code><a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a> *cancellable</code></em>);</pre> <p>The prototype for a task function to be run in a thread via <a class="link" href="GTask.html#g-task-run-in-thread" title="g_task_run_in_thread ()"><code class="function">g_task_run_in_thread()</code></a> or <a class="link" href="GTask.html#g-task-run-in-thread-sync" title="g_task_run_in_thread_sync ()"><code class="function">g_task_run_in_thread_sync()</code></a>.</p> <p>If the return-on-cancel flag is set on <em class="parameter"><code>task</code></em> , and <em class="parameter"><code>cancellable</code></em> gets cancelled, then the <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> will be completed immediately (as though <a class="link" href="GTask.html#g-task-return-error-if-cancelled" title="g_task_return_error_if_cancelled ()"><code class="function">g_task_return_error_if_cancelled()</code></a> had been called), without waiting for the task function to complete. However, the task function will continue running in its thread in the background. The function therefore needs to be careful about how it uses externally-visible state in this case. See <a class="link" href="GTask.html#g-task-set-return-on-cancel" title="g_task_set_return_on_cancel ()"><code class="function">g_task_set_return_on_cancel()</code></a> for more details.</p> <p>Other than in that case, <em class="parameter"><code>task</code></em> will be completed when the <a class="link" href="GTask.html#GTaskThreadFunc" title="GTaskThreadFunc ()"><span class="type">GTaskThreadFunc</span></a> returns, not when it calls a <code class="literal">g_task_return_</code> function.</p> <div class="refsect3"> <a name="GTaskThreadFunc.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody> <tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>the <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a></p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>source_object</p></td> <td class="parameter_description"><p><em class="parameter"><code>task</code></em> 's source object. </p></td> <td class="parameter_annotations"><span class="annotation">[<acronym title="Override the parsed C type with given type."><span class="acronym">type</span></acronym> GObject]</span></td> </tr> <tr> <td class="parameter_name"><p>task_data</p></td> <td class="parameter_description"><p><em class="parameter"><code>task</code></em> 's task data</p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>cancellable</p></td> <td class="parameter_description"><p><em class="parameter"><code>task</code></em> 's <a class="link" href="GCancellable.html" title="GCancellable"><span class="type">GCancellable</span></a>, or <code class="literal">NULL</code></p></td> <td class="parameter_annotations"> </td> </tr> </tbody> </table></div> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-attach-source"></a><h3>g_task_attach_source ()</h3> <pre class="programlisting"><span class="returnvalue">void</span> g_task_attach_source (<em class="parameter"><code><a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a> *task</code></em>, <em class="parameter"><code><span class="type">GSource</span> *source</code></em>, <em class="parameter"><code><span class="type">GSourceFunc</span> callback</code></em>);</pre> <p>A utility function for dealing with async operations where you need to wait for a <span class="type">GSource</span> to trigger. Attaches <em class="parameter"><code>source</code></em> to <em class="parameter"><code>task</code></em> 's <span class="type">GMainContext</span> with <em class="parameter"><code>task</code></em> 's <a class="link" href="GAsyncResult.html#io-priority" title="I/O Priority">priority</a>, and sets <em class="parameter"><code>source</code></em> 's callback to <em class="parameter"><code>callback</code></em> , with <em class="parameter"><code>task</code></em> as the callback's <code class="literal">user_data</code>.</p> <p>It will set the <em class="parameter"><code>source</code></em> ’s name to the task’s name (as set with <a class="link" href="GTask.html#g-task-set-name" title="g_task_set_name ()"><code class="function">g_task_set_name()</code></a>), if one has been set.</p> <p>This takes a reference on <em class="parameter"><code>task</code></em> until <em class="parameter"><code>source</code></em> is destroyed.</p> <div class="refsect3"> <a name="g-task-attach-source.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody> <tr> <td class="parameter_name"><p>task</p></td> <td class="parameter_description"><p>a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a></p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>source</p></td> <td class="parameter_description"><p>the source to attach</p></td> <td class="parameter_annotations"> </td> </tr> <tr> <td class="parameter_name"><p>callback</p></td> <td class="parameter_description"><p>the callback to invoke when <em class="parameter"><code>source</code></em> triggers</p></td> <td class="parameter_annotations"> </td> </tr> </tbody> </table></div> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> <hr> <div class="refsect2"> <a name="g-task-is-valid"></a><h3>g_task_is_valid ()</h3> <pre class="programlisting"><span class="returnvalue">gboolean</span> g_task_is_valid (<em class="parameter"><code><span class="type">gpointer</span> result</code></em>, <em class="parameter"><code><span class="type">gpointer</span> source_object</code></em>);</pre> <p>Checks that <em class="parameter"><code>result</code></em> is a <a class="link" href="GTask.html" title="GTask"><span class="type">GTask</span></a>, and that <em class="parameter"><code>source_object</code></em> is its source object (or that <em class="parameter"><code>source_object</code></em> is <code class="literal">NULL</code> and <em class="parameter"><code>result</code></em> has no source object). This can be used in <code class="function">g_return_if_fail()</code> checks.</p> <div class="refsect3"> <a name="g-task-is-valid.parameters"></a><h4>Parameters</h4> <div class="informaltable"><table class="informaltable" width="100%" border="0"> <colgroup> <col width="150px" class="parameters_name"> <col class="parameters_description"> <col width="200px" class="parameters_annotations"> </colgroup> <tbody> <tr> <td class="parameter_name"><p>result</p></td> <td class="parameter_description"><p>A <a class="link" href="GAsyncResult.html" title="GAsyncResult"><span class="type">GAsyncResult</span></a>. </p></td> <td class="parameter_annotations"><span class="annotation">[<acronym title="Override the parsed C type with given type."><span class="acronym">type</span></acronym> Gio.AsyncResult]</span></td> </tr> <tr> <td class="parameter_name"><p>source_object</p></td> <td class="parameter_description"><p>the source object expected to be associated with the task. </p></td> <td class="parameter_annotations"><span class="annotation">[<acronym title="NULL may be passed as the value in, out, in-out; or as a return value."><span class="acronym">nullable</span></acronym>][<acronym title="Override the parsed C type with given type."><span class="acronym">type</span></acronym> GObject]</span></td> </tr> </tbody> </table></div> </div> <div class="refsect3"> <a name="g-task-is-valid.returns"></a><h4>Returns</h4> <p> <code class="literal">TRUE</code> if <em class="parameter"><code>result</code></em> and <em class="parameter"><code>source_object</code></em> are valid, <code class="literal">FALSE</code> if not</p> </div> <p class="since">Since: <a class="link" href="api-index-2-36.html#api-index-2.36">2.36</a></p> </div> </div> <div class="refsect1"> <a name="GTask.other_details"></a><h2>Types and Values</h2> <div class="refsect2"> <a name="GTask-struct"></a><h3>GTask</h3> <pre class="programlisting">typedef struct _GTask GTask;</pre> <p>The opaque object representing a synchronous or asynchronous task and its result.</p> </div> </div> <div class="refsect1"> <a name="GTask.property-details"></a><h2>Property Details</h2> <div class="refsect2"> <a name="GTask--completed"></a><h3>The <code class="literal">“completed”</code> property</h3> <pre class="programlisting"> “completed” <span class="type">gboolean</span></pre> <p>Whether the task has completed, meaning its callback (if set) has been invoked. This can only happen after <a class="link" href="GTask.html#g-task-return-pointer" title="g_task_return_pointer ()"><code class="function">g_task_return_pointer()</code></a>, <a class="link" href="GTask.html#g-task-return-error" title="g_task_return_error ()"><code class="function">g_task_return_error()</code></a> or one of the other return functions have been called on the task.</p> <p>This property is guaranteed to change from <code class="literal">FALSE</code> to <code class="literal">TRUE</code> exactly once.</p> <p>The <span class="type">“notify”</span> signal for this change is emitted in the same main context as the task’s callback, immediately after that callback is invoked.</p> <p>Owner: GTask</p> <p>Flags: Read</p> <p>Default value: FALSE</p> <p class="since">Since: <a class="link" href="api-index-2-44.html#api-index-2.44">2.44</a></p> </div> </div> <div class="refsect1"> <a name="GTask.see-also"></a><h2>See Also</h2> <p><a class="link" href="GAsyncResult.html" title="GAsyncResult"><span class="type">GAsyncResult</span></a></p> </div> </div> <div class="footer"> <hr>Generated by GTK-Doc V1.32</div> </body> </html>