GTask getters don’t return TRUE/FALSE after bitfield changes
If a program uses yield
, Gtk.main_quit()
does not work as expected. Interestingly, I can only reproduce the issue when building with Flatpak. That might be due to version differences, but I'm not sure.
Here's a proof of concept (corresponding C code is attached):
async void clicked() {
File file = File.new_for_path("/dev/null");
// WORKS AS EXPECTED
/*
file.read_async.begin(Priority.DEFAULT, null, (obj, res) => {
file.read_async.end(res);
debug("done");
});
*/
// MAIN LOOP WILL NOT EXIT
yield file.read_async(Priority.DEFAULT, null);
debug("done");
}
int main (string[] args) {
Gtk.init(ref args);
var win = new Gtk.Window();
var btn1 = new Gtk.Button.with_label("Read file");
btn1.clicked.connect((button) => {
clicked.begin();
});
var btn2 = new Gtk.Button.with_label("Quit");
btn2.clicked.connect((button) => {
debug("quitting...");
Gtk.main_quit();
});
var box = new Gtk.Box(Gtk.Orientation.VERTICAL, 6);
box.add(btn1);
box.add(btn2);
win.add(box);
win.show_all();
Gtk.main();
return 0;
}
If you run this code and click "Quit", the program will quit. However, if you click "Read file" first, then "Quit", it will not quit. Note that if you use the top, commented code instead, which should be equivalent, it will work as expected.
I'm not a Vala or C expert, but this seems to be due to the while (g_task_get_completed (_data_->_async_result) != TRUE)
block in the generated clicked_co
function replacing the real main loop.