 
 : add-timer-to-run-loop ( timer -- )
     [ reset-timer ]
-    [ run-loop timers>> push ]
+    [ get-run-loop timers>> push ]
     [
         CFRunLoopGetMain
         swap CFRunLoopDefaultMode

    [
        <CFFileDescriptor> |CFRelease
        [ enable-all-callbacks ]
        [ run-loop fds>> push ]
        [ create-fd-source |CFRelease add-source-to-run-loop ]
        tri
    ] with-destructors ;


TUPLE: run-loop-state fds sources timers ;

SYMBOL: run-loop

: <run-loop> ( -- run-loop )
    V{ } clone V{ } clone V{ } clone \ run-loop-state boa ;

: get-run-loop ( -- run-loop )
    \ run-loop [ <run-loop> ] initialize-alien ;

: add-source-to-run-loop ( source -- )
    [ get-run-loop sources>> push ]
    [
        CFRunLoopGetMain
        swap CFRunLoopDefaultMode
