How to do an atomic transaction in gundb?

52 Views Asked by At

How do I do an atomic commit/transaction in GUN? https://gun.eco/docs/Transactions is a bit opaque.

I need to do multiple puts and ensure they are (eventually) executed all together without intervening changes.

1

There are 1 best solutions below

2
Lee On

Perhaps you could use the callback in put to be sure it has completed:

https://gun.eco/docs/API#-a-name-put-a-gun-put-data-callback-

let gunput = (val) => { return new Promise((res,rej) => {
    gun.get('something').put(val, function(ack){
       if(ack.err){
          res(false)
       }
       res(true)
    })
}
let tx_done = await gunput('test')
if (tx_done) // do next tx