FratmScript 🤌🏻

Async and generators

mo vir facc declares an async function (async function) and aspett waits for a Promise (await). It also works with arrows, mo vir (x) => …, and in loops, pe aspett (… dint …).

facc* name() { … } declares a generator (function*): each caccia value produces the next value (yield). Walk a generator with pe ogni or spread it.

chiamm { aspetta } da "fratm"

mo vir facc cucina(pizza) {
    stamm a dì("Inforno", pizza)
    aspett aspetta(300)
    piglie pizza + " pronta"
}

mo vir facc servizio() {
    chist è pizze = aspett Promise.all([cucina("margherita"), cucina("marinara")])
    stamm a dì(pizze.join(", "))
}

servizio()

Output

Inforno margherita
Inforno marinara
margherita pronta, marinara pronta
facc* numeri(fino) {
    pe (tien i = 1; i <= fino; i++) {
        caccia i
    }
}

pe ogni (chist è n dint numeri(3)) {
    stamm a dì(n)
}
stamm a dì([...numeri(5)].join(" "))

Output

1
2
3
1 2 3 4 5

Try this section in the playground