[Vala] Question about a basic coroutine example
- From: Serge Hulne <serge hulne gmail com>
- To: vala-list <vala-list gnome org>
- Subject: [Vala] Question about a basic coroutine example
- Date: Thu, 7 Jul 2011 21:35:41 +0200
In the snippet hereunder, I expected the respective value of the argument
of the sleep() method, in the methods foo0() and foo1(), to have an
influence on which one of said coroutines completes first.
Apparently it is not the case, so I am assuming that foo0 and foo1 run, in
fact, sequentially (and not asynchronously as would, say two children
processes, for instance).
Is there a way to modify the snippet hereunder so that the coroutine which
executes faster completes first (or like two children processes) ?
Serge.
////////////
using Posix;
MainLoop ml;
async void foo1 () {
Idle.add(foo1.callback);
yield;
for (int i=0; i<10; i++ ) message ("Foo 1");
Posix.sleep(2);
ml.quit();
}
async void foo2 () {
Idle.add(foo2.callback);
yield;
for (int i=0; i<10; i++ ) message ("Foo 2");
Posix.sleep(1);
ml.quit();
}
void main () {
foo1.begin();
foo2.begin();
ml = new MainLoop();
ml.run();
}
/////////////
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]