Hacker News new | ask | show | jobs
by Vinnl 863 days ago
Ah! You mean that

    await Promise.all(
      unneededPages.map(async (page) => {
        await fs.move(page, `scripts/.cache/${page}`, { overwrite: true });
      })
    );
could also have been written as

    await Promise.all(
      unneededPages.map((page) => {
        fs.move(page, `scripts/.cache/${page}`, { overwrite: true });
      })
    );
That is absolutely correct! I wasn't intending it as an example of how to write flawless JS code though, just as an example of the type of script that ZX is useful for - but if I remember next time I open my dev env, I'll update it :)

Edit: though maybe I'm misunderstanding given that you said it would make them run sync, because as far as I know, the functions would still run in parallel? Essentially, I believe it would roughly be the equivalent of this:

    await Promise.all(
      unneededPages.map((page) => {
        fs.move(page, `scripts/.cache/${page}`, { overwrite: true });
      }).then(result => result)
    );