- async function* getLines() {
- const data = [
- "# Commentaire ignoré",
- "Ligne utile 1",
- "Ligne utile 2",
- "# Autre commentaire",
- "STOP",
- "Ligne après STOP",
- ];
- for (const line of data) {
- await new Promise((resolve) => setTimeout(resolve, 100)); // simule un délai
- yield line;
- }
- }
- async function processUntilStop(lines) {
- for await (const line of lines) {
- if (line === "STOP") break;
- if (line.startsWith("#")) continue;
- console.log(`Traitement : ${line}`);
- }
- console.log("🔚 Fin du traitement.");
- }
- processUntilStop(getLines());