Concurent_async added.

This commit is contained in:
Kolan Sh 2018-07-26 14:45:09 +03:00
parent 8916e333a7
commit 289eb9ff5d
2 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,44 @@
bool called = false;
async void noop() {
}
async void foo_async() {
if (called) {
stdout.puts("foo_async(): wait\n");
while (called)
yield noop();
return;
}
stdout.puts("foo_async(): execute\n");
called = true;
for (var i = 0; i < 100000; ++i);
yield noop();
called = false;
}
int main() {
foo_async.begin((obj, res) => {
foo_async.end(res);
stdout.puts("1'st foo_async() ended\n");
});
foo_async.begin((obj, res) => {
foo_async.end(res);
stdout.puts("2'nd foo_async() ended\n");
});
var loop = new MainLoop();
var t = new TimeoutSource(0);
t.set_callback(() => {
loop.quit();
return false;
});
t.attach(loop.get_context());
loop.run();
return 0;
}

3
vala/concurent_async/run.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
valac --pkg=gio-2.0 concurent_async.vala && ./concurent_async