4 ms·
The other problem I see here is that starting and awaiting the task are too coupled. In JavaScript calling the function would start the task, and awaiting the
by spankalee 3y ago
The other problem I see here is that starting and awaiting the task are too coupled.
In JavaScript calling the function would start the task, and awaiting the result would wait for it. This lets you do several things concurrently.
How would you do this in Dada:
const doThings = async () => {
const [one, two, three] = await Promise.all([
doThingOne(),
doThingTwo(),
doThingThree(),
]);
};
And if you wanted to return a thunk to delay starting the work, you would just do that yourself.
- janderland 3y agoI assumed dada is using promises under the hood, just as JS is. If this is the case it could provide a static method for waiting on multiple promises, just as JS does.
- spankalee 3y agoThis seems to say otherwise (specifically the "but not running" part): Dada, like JavaScript, is based exclusively on async-await. This means that operations that perform I/O, like print, don't execute immediately. Instead, they return a thunk, which is basically "code waiting to run" (but not running yet). The thunk doesn't execute until you await it by using the .await operation. From https://dada-lang.org/docs/dyn_tutorial https://dada-lang.org/docs/dyn_tutorial