Is there a timeout for optimistic UI updates?


#1

I’m messing around with optimistic UI a bit, so I created /both/methods.js and put this in it:

Meteor.methods({
  incLikes() {
    Meteor.isServer && Meteor._sleepForMs(5000);
    Likes.update({}, {$inc: {likeCount: 1}});
  }
});

And then I have a React component that is a like button and a display that shows the value of likeCount. Of course, the likeCount is 0 and I click “Like,” on the client it increases to 1, and five seconds later the server reflects this update.

What I’m wondering is, how long will minimongo and mongo wait to be in sync? Is there a timeout where an error will be thrown? If not, how do I create this type of mechanism?


#2

The only way I’ve found to signal the client to revert back is to throw an error. This might be the answer. (or for a natural error to occur)

Meteor.methods({
  incLikes() {
    if (Meteor.isServer) {
      Meteor._sleepForMs(5000);
      throw new Meteor.Error('oops', 'Stuff went wrong');
    }
    Likes.update({}, {$inc: {likeCount: 1}});
  }
});