1

How does Meteor's optimistic UI handle server rejections and errors on dependent operations?

If I do :

var item1Id = Items.insert({list: groceriesId, name: "Watercress"}); // op1
var item = Items.findOne({_id: item1Id});
Items.update(item, {$set: {name: "Peppers"}}); // op2

Items.insert({list: groceriesId, name: "Cheese"}); // op3

If op1 fails on the server-side but succeeds on the client-side, what will happen to op2 and op3?
Will they both be rolled back?

tgogos
  • 23,218
  • 20
  • 96
  • 128
opsb
  • 29,325
  • 19
  • 89
  • 99

1 Answers1

1

If op1 fails then op2 will get rolled back (because it's an update to an object that doesn't exist). op3 will succeed assuming it doesn't also fail atomically.

If you wanted to prevent op3 from happening unless you were sure that op1 had succeeded then you could do it in a callback from op1.

Michel Floyd
  • 18,793
  • 4
  • 24
  • 39
  • A MeteorPad would be really nice here. Will you have time to make it? If not, I could scrap one quickly. – Kyll Nov 21 '15 at 14:07
  • 1
    Salut @Kyll - I started one [here](http://meteorpad.com/pad/93gBboJfJ3y2kiYN5/Leaderboard) but now need to create an error in the first insert. Care to try? – Michel Floyd Nov 22 '15 at 02:39