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

    ] tri ;

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

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



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
