for over streams
for v in x goes over an async iterable too, whose values come from [Symbol.asyncIterator]() of its .d.ts: a stream of Node, the lines of readline, the body of a request, the cursor of a database. It compiles to for await of JS, so each value waits for its Promise, as the values of a channel do, and the loop is allowed where await is. break closes the stream.
The board can process an incoming sequence of task changes with this loop, handling each change as it arrives instead of waiting for the whole feed to finish.
The types come from TypeScript declarations, such as @types/node, which the playground on this page does not have, so here is the code with what it compiles to:
import { createReadStream } from "node:fs" import { createInterface } from "node:readline" async func countErrors(path string) number { let errors = 0 for line in createInterface({ input: createReadStream(path) }) { if line.includes("ERROR") { errors++ } } return errors }
import { createReadStream } from "node:fs"; import { createInterface } from "node:readline"; async function countErrors(path) { let errors = 0; for await (const line of createInterface({ input: createReadStream(path) })) { if (line.includes("ERROR")) { errors++; } } return errors; }