Simple threads...
This commit is contained in:
parent
ca6976bda1
commit
1052fa8aae
|
@ -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();
|
||||
}
|
Loading…
Reference in New Issue