Download client.html from hysts-debug/js-client-submit-iterator-close-race: direct link, hf CLI and curl.
- Browser
- Download file 965 Bytes
-
https://huggingface.co/spaces/hysts-debug/js-client-submit-iterator-close-race/resolve/main/client.html
- Command line
-
hf download hf://spaces/hysts-debug/js-client-submit-iterator-close-race/client.html
-
curl -L -o client.html https://huggingface.co/spaces/hysts-debug/js-client-submit-iterator-close-race/resolve/main/client.html
965 Bytes
| <button id="run">run</button> | |
| <pre id="log"></pre> | |
| <script type="module"> | |
| import {Client} from "https://cdn.jsdelivr.net/npm/@gradio/client/dist/index.min.js"; | |
| const log = document.getElementById("log"); | |
| const out = (...a) => {log.textContent += a.join(" ") + "\n";}; | |
| document.getElementById("run").onclick = async () => { | |
| const client = await Client.connect(location.origin, {events: ["data"]}); | |
| const job = client.submit("/stream", {message: "test"}); | |
| const TIMEOUT = 4000; | |
| const timer = setTimeout(() => { | |
| out(`!! TIMEOUT after ${TIMEOUT}ms — iterator did not close`); | |
| job.return?.(); | |
| }, TIMEOUT); | |
| let n = 0; | |
| for await (const msg of job) { | |
| n++; | |
| out(`#${n}`, JSON.stringify({type: msg.type, stage: msg.stage})); | |
| } | |
| clearTimeout(timer); | |
| out(`exited naturally after ${n} messages`); | |
| }; | |
| </script> | |