I have this lines of code
const countryIds = intersectingBbox.split(';');
const countryFound = countryIds.some(async (id) => {
const possibleCountry = await _inBbox(id);
return _checkPointInPolygonAndDispatch(possibleCountry);
});
This _checkPointInPolygonAndDispatch() is a rather complicated function, but in the end it returns true or false. The some() runs twice. The first iteration it goes into the block of _checkPointInPolygonAndDispatch() where it returns false. The second time it goes into the block of _checkPointInPolygonAndDispatch() where it returns false, and then it breaks the iteration. Logging countryFound gives me a true. This is unexpected because in this function _checkPointInPolygonAndDispatch() it always goes into the block, where it returns false. I rewrote the whole thing to this
const countryIds = intersectingBbox.split(';');
for (let index = 0; index < countryIds.length; index++) {
const possibleCountry = await _inBbox(countryIds[index]);
const countryFound = _checkPointInPolygonAndDispatch(possibleCountry)
if (countryFound) {
break;
}
}
And this works as expected.
So I am assuming, I missunderstand some()? I thought it runs as long as something evaluates to true?!
your async function is returning a Promise which is truthy. you will have to restructure your code to handle the promises.