load_contents_async
Description:
public async bool load_contents_async (Cancellable? cancellable = null, out uint8[] contents, out string? etag_out) throws Error
Starts an asynchronous load of the this's contents.
For more details, see load_contents which is the synchronous version of this call.
When the load operation has completed, callback
will be called with user
data. To finish the operation, call
load_contents_async.end with the AsyncResult returned
by the callback
.
If cancellable
is not null, then the operation can be cancelled by triggering the cancellable
object from another thread. If the operation was cancelled, the error g_io_error_cancelled will be returned.
Example: Load content, async:
public static int main (string[] args) {
if (args.length != 2) {
print ("%s FILE\n", args[0]);
return 0;
}
MainLoop loop = new MainLoop ();
File file = File.new_for_commandline_arg (args[1]);
file.load_contents_async.begin (null, (obj, res) => {
try {
uint8[] contents;
string etag_out;
file.load_contents_async.end (res, out contents, out etag_out);
print ("%s", (string) contents);
} catch (Error e) {
print ("Error: %s\n", e.message);
}
loop.quit ();
});
loop.run ();
return 0;
}
valac --pkg gio-2.0 GLib.File.load_contents_async.vala
Parameters:
this |
input File |
cancellable |
optional Cancellable object, null to ignore |
callback |
a TaskReadyCallback to call when the request is satisfied |
user_data |
the data to pass to callback function |