dev/vala/threads/async_idle_bg_thread.vala

29 lines
590 B
Vala
Raw Normal View History

2015-08-20 21:09:58 +03:00
async double async_method() {
SourceFunc callback = async_method.callback;
double result = 0;
ThreadFunc<void*> run = () => {
stdout.puts("Thread is running!\n");
result = 3.14;
stdout.puts("Thread stopped!\n");
Idle.add((owned)callback);
return null;
};
new Thread<void*>("debugging thread name", run);
yield;
return result;
}
void main() {
MainLoop mainloop = new GLib.MainLoop();
async_method.begin((obj,res) => {
var result = async_method.end(res);
stdout.puts(@"async_method.callback()\nResult = $result\n");
mainloop.quit();
}
);
mainloop.run();
}