Reputation: 15455
If Contracts.findAll
is a promise, why do I need to put a promise around that? or do I need a promise in this interaction between these 2 files? (Note: I do want separate files, but do I need promise
and the async/await
)?
app.js
(async () => {
var results2 = await contracts.get();
console.log(results2);
})();
service.js
exports.get = function () {
return new Promise(function (resolve, reject) {
Contract.findAll().then(contracts => {
resolve(contracts[0].AccountNo_Lender)
});
});
};
Upvotes: 1
Views: 612
Reputation: 8856
You don't need a wrapper Promise if Contract.findAll()
already returns a promise.
The following code is equivalent:
exports.get = function () {
return Contract.findAll().then(
contracts => contracts[0].AccountNo_Lender
);
};
Upvotes: 3