I have the following code (db
and _db
are separate so please dont get confused):
function getValues() {
let _db = [];
database
.init()
.then(function(db) {
/* some code that inserts a list of objects into the _db array */
})
.finally(function(db) {
if (db) db.close();
});
return _db;
}
The problem is, i always get an empty _db value whenever i call getValues()
function. I know its probably something to do with async JS. But please tell me how can i get the final value of _db and not the initialized, empty value of _db.