Tom: Very clean!! And probably not too hard to modify for re-usable shreds. I'll report back. - Rob On 8 Jun 2009, at 15:18, Tom Lieber wrote:
On Mon, Jun 8, 2009 at 1:53 PM, Robert Poor
wrote: 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/ _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users