dev/vala/threads/async_idle.vala

20 lines
752 B
Vala

class Test.Async : GLib.Object {
public async string say(string sentence) {
GLib.Idle.add(this.say.callback); // Useful in background threads
yield; // (yield called in the parent(main) thread).
return sentence;
}
public static int main(string[] args) {
Test.Async myasync = new Test.Async();
GLib.MainLoop mainloop = new GLib.MainLoop();
myasync.say.begin("helloworld",
(obj, res) => {
string sentence = myasync.say.end(res);
print("%s\n", sentence);
mainloop.quit();
});
mainloop.run();
return 0;
}
}