Bear with me as a Java programmer, learning modern JavaScript on a new project. I get the concept of Promises for handling asynchronous operations but is there a reason to "promisify" code, that intensity-wise does next to nothing and doesnt contain anything you need to wait for (like db query, http request etc.)? I've run into this backend node.js code that does trivial stuff inside a promise:
const customersWithHeader; //assume this contains an array of rows loaded from CSV file
const allowedHeaderNames; //assume a string array with allowed header names (6 values)
return new Promise((resolve, reject) =>
allowedHeaderNames.find((name, index) => name !== customersWithHeader[0][index])
? reject({error: 'missing-header'})
: resolve(customersWithHeader.slice(1))
).then(/* Then follows code that does db queries on every row from the customer array, those are promisified by Promise.all() */)
There is nothing to wait for, just checking one tiny array against another. What is the benefit of writing such code instead of just having an if and synchronously returning the sliced array or throwing an error? To me it just seems like needlessly instantiating Promise.