News for hackers. Stuff that matters.
Re:Understanding Node.js Event-Driven Architecture by shawndellysse on Tuesday May 09, 2017 @11:02AM (#14300610)
mz (https://www.npmjs.com/package/mz) is my go-to. You just prefix the core lib ("fs") with "mz/" ("mz/fs") and you get the promised version.

    const fs = require("fs");
    fs.exists(`${ __dirname }/1`, (exists1) => {
      fs.exists(`${ __dirname }/2`, (exists2) => {
        console.log(JSON.stringify([exists1, exists2]));
      });
    });
vs

    const fs = require("mz/fs");
    Promise.all([
      fs.exists(`${ __dirname }/1`),
      fs.exists(`${ __dirname }/2`),
    ])
    .then((existers) => {
      console.log(JSON.stringify(existers));
    });
Or

    const fs = require("mz/fs");
    (async () => {
      console.log(JSON.stringify(await Promise.all([
        fs.exists(`${ __dirname }/1`),
        fs.exists(`${ __dirname }/2`),
      ])));
    })();

There are no comments on this comment yet.