Wednesday, 15 March 2017

How to know if the insert function to arangodb is done successfully in ArangoJS?

this is my code snippet in inserting document using arangojs and aqb:

1. addPatient:(patient) => {
2.     
3.     let isSuccess = true;
4.
5.   db.query(qb.insert(qb(patient)).into('patient')).then((cursor) => {
6.        console.log("then() was called, isSuccess is:" + isSuccess);
7.    }).catch((err) => {
8.        isSuccess = false;
9.        console.log("catch() was called, isSuccess is: " + isSuccess);
10.    });
11.   
12.    console.log("returning isSuccess, isSuccess is: " + isSuccess);
13.    return isSuccess;
14. }

The purpose of the code above will accept a patient object, ussually a JSON object then return true if the then() function was called, and false if the catch() function was called.

lets assume that the catch() was called,

My problem is that the line 12 was first executed before line 7. so the function addPatient() return true rather than false.

this is the console result

enter image description here



via Gerald

No comments:

Post a Comment