abe56ce16e02846562c73e8373fc22c2a604e511
[platform/upstream/pygobject2.git] / docs / reference / pygio-asyncresult.xml
1 <?xml version="1.0" standalone="no"?>
2 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
3     "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
4
5 <refentry id="class-gioasyncresult">
6     <refnamediv>
7         <refname>gio.AsyncResult</refname>
8         <refpurpose>Asynchronous Function Results.</refpurpose>
9     </refnamediv>
10
11     <refsect1>
12         <title>Synopsis</title>
13
14     <classsynopsis language="python">
15         <ooclass><classname>gio.AsyncResult</classname></ooclass>
16         <ooclass><classname><link linkend="class-gobjectginterface">gobject.GInterface</link></classname></ooclass>
17
18     <methodsynopsis language="python">
19         <methodname><link linkend="method-gioasyncresult--get-source-object">get_source_object</link></methodname>
20         <methodparam></methodparam>
21     </methodsynopsis>
22     
23     </classsynopsis>
24
25     </refsect1>
26
27     <refsect1>
28         <title>Ancestry</title>
29
30 <synopsis>+-- <link linkend="class-gobjectginterface">gobject.GInterface</link>
31   +-- <link linkend="class-gioasyncresult">gio.AsyncResult</link>
32 </synopsis>
33
34     </refsect1>
35     
36     <refsect1>
37         <title>Prerequisites</title>
38         <para>
39             <link linkend="class-gioasyncresult"><classname>gio.AsyncResult</classname></link> is required by
40             <link linkend="class-gobject"><classname>gobject.GObject</classname></link>.
41         </para>
42     </refsect1>
43     
44     <refsect1>
45         <title>Known Implementation</title>
46         <para>
47             <link linkend="class-gioasyncresult"><classname>gio.AsyncResult</classname></link> is implemented by
48             <link linkend="class-giosimpleasyncresult"><classname>gio.SimpleAsyncResult</classname></link>.
49         </para>
50     </refsect1>
51
52     <refsect1>
53         <title>Description</title>
54
55         <para>
56             <link linkend="class-gioasyncresult"><classname>gio.AsyncResult</classname></link>
57             provides a base class for implementing asynchronous function results.
58         </para>
59         <para>
60             Asynchronous operations are broken up into two separate operations which are chained
61             together by a GAsyncReadyCallback. To begin an asynchronous operation, provide a
62             GAsyncReadyCallback to the asynchronous function. This callback will be triggered when
63             the operation has completed, and will be passed a GAsyncResult instance filled with the
64             details of the operation's success or failure, the object the asynchronous function was
65             started for and any error codes returned. The asynchronous callback function is then expected
66             to call the corresponding "_finish()" function with the object the function was called for,
67             and the <link linkend="class-gioasyncresult"><classname>gio.AsyncResult</classname></link>
68             instance, and optionally, an error to grab any error conditions that may have occurred. 
69         </para>
70         <para>
71             The purpose of the "_finish()" function is to take the generic result of type GAsyncResult and
72             return the specific result that the operation in question yields (e.g. a
73             <link linkend="class-giofileenumerator"><classname>gio.FileEnumerator</classname></link>
74             for a "enumerate children" operation). If the result or error status of the operation is not needed,
75             there is no need to call the "_finish()" function, GIO will take care of cleaning up the result and error
76             information after the GAsyncReadyCallback returns. It is also allowed to take a reference to the
77             <link linkend="class-gioasyncresult"><classname>gio.AsyncResult</classname></link>
78             and call "_finish()" later. 
79         </para>
80         <para>
81             The callback for an asynchronous operation is called only once, and is always called, even
82             in the case of a cancelled operation. On cancellation the result is a gio.ERROR_CANCELLED error. 
83         </para>
84         <para>
85             Some ascynchronous operations are implemented using synchronous calls. These are run in a
86             separate thread, if GThread has been initialized, but otherwise they are sent to the Main Event
87             Loop and processed in an idle function. So, if you truly need asynchronous operations, make
88             sure to initialize GThread.
89         </para>
90     </refsect1>
91
92     <refsect1>
93         <title>Methods</title>
94
95         <refsect2 id="method-gioasyncresult--get-source-object">
96             <title>gio.AsyncResult.get_source_object</title>
97
98             <programlisting><methodsynopsis language="python">
99                 <methodname>get_source_object</methodname>
100                 <methodparam></methodparam>
101             </methodsynopsis></programlisting>
102             
103             <variablelist>
104                 <varlistentry>
105                     <term><emphasis>Returns</emphasis>&nbsp;:</term>
106                     <listitem><simpara>the source object for the res.                        
107                     </simpara></listitem>
108                 </varlistentry>
109             </variablelist>
110     
111             <para>
112                 The <methodname>get_source_object</methodname>() method gets the source object
113                 from a <link linkend="class-gioasyncresult"><classname>gio.AsyncResult</classname></link>
114             </para>
115         </refsect2>
116     </refsect1>
117 </refentry>