Is the insertion order guaranteed with this example code?

Taking the following code which is found at https://tinkerpop.apache.org/docs/current/reference/#gremlin-javascript-transactions, is the insertion order guaranteed for these two new vertices?

const g = traversal().withRemote(new DriverRemoteConnection('ws://localhost:8182/gremlin'));
const tx = g.tx(); // create a Transaction

// spawn a new GraphTraversalSource binding all traversals established from it to tx
const gtx = tx.begin();

// execute traversals using gtx occur within the scope of the transaction held by tx. the
// tx is closed after calls to commit or rollback and cannot be re-used. simply spawn a
// new Transaction from g.tx() to create a new one as needed. the g context remains
// accessible through all this as a sessionless connection.
Promise.all([
  gtx.addV("person").property("name", "jorge").iterate(),
  gtx.addV("person").property("name", "josh").iterate()
]).then(() => {
  return tx.commit();
}).catch(() => {
  return tx.rollback();
});
Solution
right, there are no any guaranties with Promise.all

if for some reason the insertion order is important, then you need to call sequentially
gtx.addV("person").property("name", "jorge").iterate(); gtx.addV("person").property("name", "josh").iterate();

this is critical for mergeE/mergeV to avoid concurrent mergeV to add/update Vertex and mergeE which will use this Vertex
Was this page helpful?