 ! Copyright (C) 2005, 2008 Slava Pestov, Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors assocs boxes calendar
-combinators.short-circuit fry heaps init kernel math.order
+USING: accessors assocs boxes calendar combinators.short-circuit
+continuations fry heaps init kernel math.order
 namespaces quotations threads math system ;
 IN: alarms
 

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

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

    interval
    { entry box } ;

SYMBOL: alarms
SYMBOL: alarm-thread

: cancel-alarm ( alarm -- )
    entry>> [ alarms get-global heap-delete ] if-box? ;

<PRIVATE

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