Simple threads...

This commit is contained in:
Kolan Sh 2015-08-20 18:28:02 +03:00
parent ca6976bda1
commit 1052fa8aae
1 changed files with 26 additions and 0 deletions

View File

@ -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();
}