Added methods for creating an interval that execute a Runnable when they

expire. Whoa, composable software. Amazing. We should have done this eight
years ago.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2595 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
samskivert
2009-07-20 22:07:29 +00:00
parent 8510eaee93
commit 8ac364d1d2
@@ -46,6 +46,34 @@ public abstract class Interval
public Interval getInterval ();
}
/**
* Creates an interval that executes the supplied runnable when it expires.
*/
public static Interval create (final Runnable onExpired)
{
return new Interval() {
public void expired () {
onExpired.run();
}
};
}
/**
* Creates an interval that executes the supplied runnable on the specified RunQueue when it
* expires.
*/
public static Interval create (RunQueue runQueue, final Runnable onExpired)
{
// we could probably avoid all the wacky machinations internal to Interval that do the
// runbuddy reposting and whatever and just create a non-runqueue interval that posts the
// supplied runnable to the runqueue when it expires, but we'll just punt on that for now
return new Interval(runQueue) {
public void expired () {
onExpired.run();
}
};
}
/**
* This may be removed.
*