Create  Edit  FrontPage  Index  Search  Changes  History  RSS  Login


module GLib::AsyncResult

Provides a base class for implementing asynchronous function results.

Asynchronous operations are broken up into two separate operations which are chained together by a block. To begin an asynchronous operation, provide a block to the asynchronous function. This block will be called when the operation has completed, and will be passed a GLib::AsyncResult instance filled with the details of the operation’s success or failure, the object the asynchronous method was started for and any error codes returned. The asynchronous callback block is then expected to call the corresponding “_finish” method on the object that the method was invoked on, along with the GLib::AsyncResult instance.

The “_finish” method for an operation takes the generic result (of type GLib::AsyncResult) and returns the specific result that the operation in question yields (for example, a GLib::FileEnumerator 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 block returns. Applications may also take a reference to the GLib::AsyncResult and call “_finish()” later; however, the “_finish()” function may be called at most once.

The callback for an asynchronous operation is called only once, and is always called, even in the case of a cancelled operation. On cancellation a GLib::IO::CancelledError is raised.

Some asynchronous operations are implemented using synchronous calls. These are run in a separate thread, if GLib::Thread 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 GLib::Thread.

Instance Methods

Gets the source object from a GLib::AsyncResult.