console.table(row)); db.each = util.promis" /> console.table(row)); db.each = util.promis" /> console.table(row)); db.each = util.promis"/>

How does promisify know which variable to return?

277 Views Asked by At

I used util.promisify on this sqlite3 function:

// Before
db.each("Select * from example;", (error, row) => console.table(row));
db.each = util.promisify(db.each);
// After
async function getRow()
     try {
        console.table(await db.each("Select * from example;")); // line 7
     } catch (e) {
        console.error(e.message);
     }
}

My question is, how does promisify know which variable (the "err" or the "row") to return in line 7?

1

There are 1 best solutions below

2
Rupjyoti On BEST ANSWER

The util.promisify() is used/able to convert a callback into promise only if the first parameter of the callback function is the error parameter.

So, it will always return "row" in Line 7. If there is an error, it will go to the catch block.