From 1052fa8aaefa9790a8f0c6dfeaa902c6e1ee341d Mon Sep 17 00:00:00 2001 From: Kolan Sh Date: Thu, 20 Aug 2015 18:28:02 +0300 Subject: [PATCH] Simple threads... --- vala/threads/async_ex.vala | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 vala/threads/async_ex.vala 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(); +}