On Mon, Jun 8, 2009 at 1:53 PM, Robert Poor
In real-time music making, sometimes you want to wait for a signal (e.g. event.broadcast()) OR for a specific time to elapse, whichever comes first.
I don't re-use shreds, but I think this is useful anyway: --- class NoteEvent extends Event { 0 => int sent; } public class Timeout { fun Event either(Event ev, dur d) { NoteEvent real; spork ~ time_alert(real, d); spork ~ event_alert(real, ev); return real; } fun void time_alert(NoteEvent real, dur d) { d => now; if(!real.sent) real.broadcast(); 1 => real.sent; } fun void event_alert(NoteEvent real, Event ev) { ev => now; if(!real.sent) real.broadcast(); 1 => real.sent; } } --- It's used like: Timeout tout; tout.either(some_event, 3::second) => now; -- Tom Lieber http://AllTom.com/