diff --git a/vala/concurent_async/concurent_async.vala b/vala/concurent_async/concurent_async.vala new file mode 100644 index 0000000..92feef1 --- /dev/null +++ b/vala/concurent_async/concurent_async.vala @@ -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; +} diff --git a/vala/concurent_async/run.sh b/vala/concurent_async/run.sh new file mode 100755 index 0000000..4ef6c2f --- /dev/null +++ b/vala/concurent_async/run.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +valac --pkg=gio-2.0 concurent_async.vala && ./concurent_async