summaryrefslogtreecommitdiff
path: root/docs/reference/pygio-asyncresult.xml
blob: abe56ce16e02846562c73e8373fc22c2a604e511 (plain)
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
<?xml version="1.0" standalone="no"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
    "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">

<refentry id="class-gioasyncresult">
    <refnamediv>
        <refname>gio.AsyncResult</refname>
        <refpurpose>Asynchronous Function Results.</refpurpose>
    </refnamediv>

    <refsect1>
        <title>Synopsis</title>

    <classsynopsis language="python">
        <ooclass><classname>gio.AsyncResult</classname></ooclass>
        <ooclass><classname><link linkend="class-gobjectginterface">gobject.GInterface</link></classname></ooclass>

    <methodsynopsis language="python">
        <methodname><link linkend="method-gioasyncresult--get-source-object">get_source_object</link></methodname>
        <methodparam></methodparam>
    </methodsynopsis>
    
    </classsynopsis>

    </refsect1>

    <refsect1>
        <title>Ancestry</title>

<synopsis>+-- <link linkend="class-gobjectginterface">gobject.GInterface</link>
  +-- <link linkend="class-gioasyncresult">gio.AsyncResult</link>
</synopsis>

    </refsect1>
    
    <refsect1>
	<title>Prerequisites</title>
        <para>
            <link linkend="class-gioasyncresult"><classname>gio.AsyncResult</classname></link> is required by
            <link linkend="class-gobject"><classname>gobject.GObject</classname></link>.
        </para>
    </refsect1>
    
    <refsect1>
	<title>Known Implementation</title>
        <para>
            <link linkend="class-gioasyncresult"><classname>gio.AsyncResult</classname></link> is implemented by
            <link linkend="class-giosimpleasyncresult"><classname>gio.SimpleAsyncResult</classname></link>.
        </para>
    </refsect1>

    <refsect1>
        <title>Description</title>

        <para>
            <link linkend="class-gioasyncresult"><classname>gio.AsyncResult</classname></link>
            provides a base class for implementing asynchronous function results.
        </para>
        <para>
            Asynchronous operations are broken up into two separate operations which are chained
            together by a GAsyncReadyCallback. To begin an asynchronous operation, provide a
            GAsyncReadyCallback to the asynchronous function. This callback will be triggered when
            the operation has completed, and will be passed a GAsyncResult instance filled with the
            details of the operation's success or failure, the object the asynchronous function was
            started for and any error codes returned. The asynchronous callback function is then expected
            to call the corresponding "_finish()" function with the object the function was called for,
            and the <link linkend="class-gioasyncresult"><classname>gio.AsyncResult</classname></link>
            instance, and optionally, an error to grab any error conditions that may have occurred. 
        </para>
        <para>
            The purpose of the "_finish()" function is to take the generic result of type GAsyncResult and
            return the specific result that the operation in question yields (e.g. a
            <link linkend="class-giofileenumerator"><classname>gio.FileEnumerator</classname></link>
            for a "enumerate children" operation). If the result or error status of the operation is not needed,
            there is no need to call the "_finish()" function, GIO will take care of cleaning up the result and error
            information after the GAsyncReadyCallback returns. It is also allowed to take a reference to the
            <link linkend="class-gioasyncresult"><classname>gio.AsyncResult</classname></link>
            and call "_finish()" later. 
        </para>
        <para>
            The callback for an asynchronous operation is called only once, and is always called, even
            in the case of a cancelled operation. On cancellation the result is a gio.ERROR_CANCELLED error. 
        </para>
        <para>
            Some ascynchronous operations are implemented using synchronous calls. These are run in a
            separate thread, if GThread has been initialized, but otherwise they are sent to the Main Event
            Loop and processed in an idle function. So, if you truly need asynchronous operations, make
            sure to initialize GThread.
        </para>
    </refsect1>

    <refsect1>
        <title>Methods</title>

        <refsect2 id="method-gioasyncresult--get-source-object">
            <title>gio.AsyncResult.get_source_object</title>

            <programlisting><methodsynopsis language="python">
                <methodname>get_source_object</methodname>
                <methodparam></methodparam>
            </methodsynopsis></programlisting>
            
            <variablelist>
                <varlistentry>
                    <term><emphasis>Returns</emphasis>&nbsp;:</term>
                    <listitem><simpara>the source object for the res.                        
                    </simpara></listitem>
                </varlistentry>
            </variablelist>
    
            <para>
                The <methodname>get_source_object</methodname>() method gets the source object
                from a <link linkend="class-gioasyncresult"><classname>gio.AsyncResult</classname></link>
            </para>
        </refsect2>
    </refsect1>
</refentry>