Question

Is it possible to determine when a ChucK child shred has finished executing if you have a reference to the child shred? For example, in this code:

// define function go()
fun void go()
{
    // insert code
}

// spork another, store reference to new shred in offspring
spork ~ go() => Shred @ offspring;

Is it possible to determine when offspring is done executing?

Was it helpful?

Solution

I'd say so, let me quote from the "VERSIONS" file from the latest release;

  - (added) int Shred.done()  // is the shred done?
            int Shred.running()  // is the shred running? 

I'm not 100% sure what "running" is supposed to refer to (perhaps I misunderstand it?) but "done" seems to suit your needs;

================== 8<================

fun void foo()
    {
    second => now;
    }

spork ~ foo() @=> Shred bar;

<<<bar.done()>>>;
<<<bar.running()>>>; // why is this 0? Bug?
2::second => now;
<<<bar.done()>>>;
<<<bar.running()>>>;

==========8<======================

Please note that calling these on a Shred object with no shred process attached to it will return more or less random numbers which is probably a bug.

---Answer from Kassen on chuck-users mailing list.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top