Paste: delayloop utility
Author: | too_embarrassed_to_admit |
Mode: | factor |
Date: | Wed, 29 Jul 2009 00:07:05 |
Plain Text |
USING: accessors calendar combinators continuations fry kernel
locals sequences threads ;
IN: delayloop
GENERIC: stall ( obj -- )
GENERIC: slow-down ( obj -- )
TUPLE: staller interval ;
: <staller> ( -- obj ) instant staller boa ;
M: staller stall ( obj -- )
interval>> sleep ;
M: staller slow-down ( obj -- )
[ 100 milliseconds time+ ] change-interval drop ;
ERROR: need-to-slow-down ;
:: delay-retry ( param quot staller -- obj )
[
[
staller stall
[ param quot call return ]
[ dup need-to-slow-down? [ drop ] [ rethrow ] if
staller slow-down
] recover
t
] loop
] with-return ; inline
: delay-each ( seq quot -- )
<staller> '[ _ _ delay-retry ] each ; inline
New Annotation