 
 TUPLE: run-loop-state fds sources timers ;
 
+SYMBOL: run-loop
+
 : <run-loop> ( -- run-loop )
     V{ } clone V{ } clone V{ } clone \ run-loop-state boa ;
 
-: run-loop ( -- run-loop )
-    \ run-loop-state [ <run-loop> ] initialize-alien ;
+: get-run-loop ( -- run-loop )
+    \ run-loop [ <run-loop> ] initialize-alien ;
 
 : add-source-to-run-loop ( source -- )
-    [ run-loop sources>> push ]
+    [ get-run-loop sources>> push ]
     [
         CFRunLoopGetMain
         swap CFRunLoopDefaultMode


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

    ] tri ;

: invalidate-run-loop-timers ( -- )
    get-run-loop [
        [ [ CFRunLoopTimerInvalidate ] [ CFRelease ] bi ] each
        V{ } clone
    ] change-timers drop ;

: reset-run-loop ( -- )
    get-run-loop
    [ timers>> [ reset-timer ] each ]
    [ fds>> [ enable-all-callbacks ] each ] bi ;

