I'm trying to perform, with ldapjs, a search for which the filter depends on the result of a first search
ldapClient.search(base1, opts1, (err1, res1) => {
res1.on("searchEntry", entry => {
const myObj = { attr1: entry.object.attr1 }
const opts2 = { filter: entry.object.filter }
if (entry.object.condition == myCondition) {
ldapClient.search(base2, opts2, (err2, res2) => {
res2.on("searchEntry", entry => {
myObj.attr2 = entry.object.attr2
});
});
}
console.log(myObj);
});
});
The problem is that when console.log displays my object in the end, the event ".on" of my second search has not been traited yet.
So, how to tell my code to wait for the second event to finish, before display the object ?
Thanks