read_async


Description:

public virtual async FileInputStream read_async (int io_priority = DEFAULT, Cancellable? cancellable = null) throws Error

Asynchronously opens this for reading.

For more details, see read which is the synchronous version of this call.

When the operation is finished, callback will be called. You can then call read_async.end to get the result of the operation.

Example: Read, async:

public static int main (string[] args) {
MainLoop loop = new MainLoop ();

File file = File.new_for_path ("my-test.txt");
file.read_async.begin (Priority.DEFAULT, null, (obj, res) => {
try {
FileInputStream @is = file.read_async.end (res);
DataInputStream dis = new DataInputStream (@is);
string line;

while ((line = dis.read_line ()) != null) {
print ("%s\n", line);
}
} catch (Error e) {
print ("Error: %s\n", e.message);
}

loop.quit ();
});

loop.run ();
return 0;
}

valac --pkg gio-2.0 GLib.File.read_async.vala

Parameters:

this

input File

io_priority

the I/O priority of the request

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