Hi Ollie,
All is good except that you probably want to make a static TheEvent
somewhere and use that one instance among the shreds. slightly modified
code below, with a new class 'The' to hold the global/static object(s).
to run:
> chuck TheEvent The events
========================= TheEvent.ck =========================
public class TheEvent extends Event
{
int value;
}
========================= The.ck ==============================
public class The
{
// declare static reference to TheEvent
// (due to 'static' not fully implemented for objects)
static TheEvent @ e;
}
// instantiate out here
// (due to 'static' not fully implemented for objects)
new TheEvent @=> The.e;
========================= events.ck =========================
machine.add( "events2.ck" );
machine.add( "events2.ck" );
machine.add( "events2.ck" );
machine.add( "events2.ck" );
// infinite time loop
while( true )
{
// advance time
1::second => now;
// set data
math.rand2( 0, 5 ) => The.e.value;
// signal one waiting shred
The.e.signal();
<<<"signaling">>>;
}
========================= events2.ck =========================
// loop
while( true )
{
// wait on event
The.e => now;
// get the data
<<