diff --git a/vala/threads/async_ex.vala b/vala/threads/async_ex.vala new file mode 100644 index 0000000..884b464 --- /dev/null +++ b/vala/threads/async_ex.vala @@ -0,0 +1,26 @@ +async void long_operation() {} + +async void async_method(int idx, int max, MainLoopKeeper mlk) { + for(var i = 0; i < max; ++i) { + stdout.puts(@"async$idx:$i\n"); + yield long_operation(); + } +} + +public class MainLoopKeeper { + MainLoop _loop; + public MainLoopKeeper(MainLoop loop) { _loop = loop; } + ~MainLoopKeeper() { _loop.quit(); } +} + +void start_methods(MainLoop loop) { + var mlk = new MainLoopKeeper(loop); + async_method.begin(1, 8, mlk); + async_method.begin(2, 3, mlk); +} + +void main() { + var loop = new MainLoop(); + start_methods(loop); + loop.run(); +}