Current.SwitchSourceLike Lwt_switch, but the cleanup functions are called in sequence, not in parallel.
A switch limits the lifetime of an operation. Cleanup operations can be registered against the switch and will be called (in reverse order) when the switch is turned off.
add_hook_or_exec switch fn pushes fn on to the stack of functions to call when t is turned off. If t is already off, calls fn immediately. If t is in the process of being turned off, waits for that to complete and then runs fn.
turn_off t marks the switch as being turned off, then pops and calls clean-up functions in order. When the last one finishes, the switch is marked as off and cannot be used again. If the switch is already off, this does nothing. If the switch is already being turned off, it just waits for that to complete.