I like this a lot!
"Very clean!!" --> It's my contention that it looks "clean" because it
doesn't bother to reuse threads, er shreds. All I'm saying is that I
spawn tens of thousands of shreds that don't get reclaimed and I never
leak enough memory to do damage during a concert. But that's just me.
-Mike
On Mon, Jun 8, 2009 at 6:18 PM, Tom Lieber
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