Currently, I am utilizing the mongodb driver to establish a connection with mongo:
public listUsers(filterSurname?:string):any {
if (this.connected) {
debug.log(this.db);
var results;
this.db.collection('userProfiles').find({}).toArray((err:Error, res:any[])=> {
if (err) return 'getting results error'
else {
results=res;
results = res;
}
return res;
});
}
debug.log('sending results' + results);
if (results !== null) {
return results;
}
else return 'connection error';
return 'db unknown error'
}
The function to array has the following signature:
toArray(callback: (err: Error, results: any[]) => any) : void;
I am looking for a way to return the value back to the function from the callback without adding another callback. Would there be an alternate solution or does TypeScript offer a resolution for callback hell?