Skip to content

Infinite patch loop when applying reversePatch after a rejected request in onPatch #1682

Answered by EmilTholin
cdes asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @cdes!

I'm not sure if there is a better way of fixing this, but I ran into this problem myself recently, and ended up temporarily disposing the patch listener, applying the reverse patch, and then started listening to patches again.

In you example, that would be something like:

let disposer: IDisposer;

function unlisten() {
  disposer();
}

function listen() {
  disposer = onPatch(store, async (patch, reversePatch) => {
    new Promise((resolve, reject) => {
      setTimeout(() => reject("fail"), 1000);
    }).catch((error) => {
      unlisten();
      applyPatch(store, reversePatch);
      listen();
    });
  });
}

listen();

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@cdes
Comment options

@EmilTholin
Comment options

@cdes
Comment options

Answer selected by cdes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants