I have an async function that supposed to return a boolean if an entity exist based on a previous request call. Here is how it looks like:
async vertexExists(properties) {
const nbVertices = await this.countVertices(properties);
if (nbVertices !== 0) {
return true;
}
return false;
}
Then in another function I call vertexExists:
if (await !this.vertexExists(entity)) {
const response = await this.gremlinQuery(query);
return response.body.result.data;
}
But it seems not to wait nbVertices to be resolved and instead tells me immediately false.
Now, I know asynchronous functions are supposed to return a Promise and not a boolean but is there anyway to have a similar behaviour?
Did I miss anything?
You are negating the promise object. You will need to use
if (!(await this.vertexExists(entity))) {
or
if (await this.vertexExists(entity).then(x => !x)) {
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With