Cancel actions in async function if observables change? #3368
-
Hey! Hoping someone has a more elegant solution to this than what I'm doing... I'm trying to think of a better way to do it, and I'm not sure if mobx has a built in way of handling this. What I'm trying to do: I've got a reaction that reacts to an observable, let's just call it The problem with this is if You also cannot wait for the promise chain to complete before performing the next promise chain. As the user needs the store to update immediately to the next promise chain that's being invoked. So, what I'm doing is keeping a timestamp that's specific to each invocation of the promise chain and then storing it globally. I've then created a wrapper function that checks the timestamp that's specific to the promise chain, and what the global timestamp is. If they match, then the action is performed, if they don't, then it does not perform the action. Curious if anyone has seen this before, or has a more elegant approach? It'd be nice if it was possible to cancel all actions within the context of a particular promise chain w/ some built in functionality. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
What you described is not to "cancel actions" but rather to "cancel a series of promises(or async code blocks if written with async/await syntax sugar) where those actions are in". Since you want an elegant solution, this is not what mobx cares about, but what Rxjs is for. The most common universal solution of cancelling a series of async behaviors is Rxjs's observable pattern. |
Beta Was this translation helpful? Give feedback.
-
Hey @inf3rnus ! |
Beta Was this translation helpful? Give feedback.
What you described is not to "cancel actions" but rather to "cancel a series of p…