I have a function that returns an object with different functions that I can use. I want to incorporate promises into these functions for better asynchronous handling.
var DATABASE = (function () {
var exports = {};
exports.query = function(filter = {}) {
return true;
}
return exports;
}());
console.log(DATABASE.query());
I attempted to make this function async, but I encountered an error stating "DATABASE.query is not a function."
var DATABASE = (async function () {
var exports = {};
exports.query = await function(filter = {}) {
return true;
}
return exports;
}());
console.log(DATABASE.query());
I also tried using promises, which seemed to work fine. However, I believe using await/async would be more efficient in terms of coding.
var DATABASE = (function () {
var exports = {};
exports.query = function(filter = {}) {
return new Promise(function(resolve, reject) {
resolve(true);
});
}
return exports;
}());
DATABASE.query().then(function(result) {
console.log(result);
});
Is there a way you can assist me in converting this code to utilize async/await instead?