 
 : cancel-alarms ( alarms -- )
     [
-        heap-pop-all [ nip alarm-entry box> drop ] assoc-each
+        heap-pop-all [ nip entry>> box> drop ] assoc-each
     ] when* ;
 
 : init-alarms ( -- )

! Copyright (C) 2005, 2008 Slava Pestov, Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: arrays calendar combinators generic init kernel math
namespaces sequences heaps boxes threads debugger quotations
assocs math.order ;
IN: alarms

TUPLE: alarm quot time interval entry ;

<PRIVATE


: notify-alarm-thread ( -- )
    alarm-thread get-global interrupt ;

ERROR: bad-alarm-frequency frequency ;
: check-alarm ( frequency/f -- frequency/f )
    dup [ duration? ] [ not ] bi or [ bad-alarm-frequency ] unless ;

: <alarm> ( quot time frequency -- alarm )
    check-alarm <box> alarm boa ;

: register-alarm ( alarm -- )
    dup dup time>> alarms get-global heap-push*
    swap entry>> >box
    notify-alarm-thread ;

: alarm-expired? ( alarm now -- ? )
    [ time>> ] dip before=? ;

: reschedule-alarm ( alarm -- )
    dup [ swap interval>> time+ ] change-time register-alarm ;

: call-alarm ( alarm -- )
    [ entry>> box> drop ]
    [ quot>> "Alarm execution" spawn drop ]
    [ dup interval>> [ reschedule-alarm ] [ drop ] if ] tri ;

: (trigger-alarms) ( alarms now -- )
    over heap-empty? [
