     >>handle
     V{ } clone swap processes get set-at
     wait-flag get-global raise-flag ;
+
+: notify-exit ( process status -- )
+    >>status
+    [ processes get delete-at* drop [ resume ] each ] keep
+    f >>handle drop ;
 
 : pass-environment? ( process -- ? )
     dup environment>> assoc-empty? not

USING: accessors assocs calendar combinators concurrency.flags
debugger destructors environment fry init io io.backend
io.encodings io.encodings.utf8 io.pipes io.pipes.private
io.ports io.streams.duplex io.timeouts kernel namespaces
prettyprint sequences strings system threads vocabs ;

IN: io.launcher


<PRIVATE

SYMBOL: wait-flag
SYMBOL: wait-delay

: wait-loop ( -- )
    processes get assoc-empty? [
        5 wait-delay set-global
        wait-flag get-global lower-flag
    ] [
        (wait-for-processes) [
            wait-delay [
                [ milliseconds sleep ] [ 5 + 100 max ] bi
            ] change-global
        ] when
    ] if ;

: start-wait-thread ( -- )
    <flag> wait-flag set-global
    5 wait-delay set-global
    [ wait-loop t ] "Process wait" spawn-server drop ;

[
