| 1 | // Copyright 2026 Deno Land Inc. Apache-2.0 license. |
| 2 | |
| 3 | //! Cell-isolate dispatch decisions, reified sans-IO. A cell isolate runs one |
| 4 | //! event at a time. A top-level Worker fetch takes the resident-isolate fast |
| 5 | //! path only when the isolate is idle; if the isolate is already pumping an |
| 6 | //! actor event, the fetch must reschedule to the stateless Worker pool — never |
| 7 | //! run nested — carrying its request identity so the reply still lands |
| 8 | //! (`js.rs`). The executor and the production run loop hold the isolate |
| 9 | //! channels and the pool; this is the pure routing they consult, so a |
| 10 | //! deterministic executor can drive it directly. |
| 11 | //! |
| 12 | //! Small protocol sequencing choices also live here when the executor owns |
| 13 | //! the bytes but not the decision. That keeps the shell mechanical and lets |
| 14 | //! callers exercise the same branch production takes. |
| 15 | |
| 16 | /// Select the protocol close code the shell must echo after the application |
| 17 | /// close handler has run and all of its output has been written. |
| 18 | /// |
| 19 | /// An application-selected close wins. Otherwise RFC 6455 requires a clean |
| 20 | /// peer close to receive a close response; 1005 is the local sentinel for a |
| 21 | /// frame with no status and cannot itself appear on the wire, so it becomes |
| 22 | /// the normal close code 1000. An abnormal transport end receives no frame. |
| 23 | pub fn websocket_echo_close( |
| 24 | peer_code: u16, |
| 25 | peer_was_clean: bool, |
| 26 | handler_sent_close: bool, |
| 27 | ) -> Option<u16> { |
| 28 | if !peer_was_clean || handler_sent_close { |
| 29 | None |
| 30 | } else if peer_code == 1005 { |
| 31 | Some(1000) |
| 32 | } else { |
| 33 | Some(peer_code) |
| 34 | } |
| 35 | } |