Skip to content

Cancel actions in async function if observables change? #3368

Answered by TotooriaHyperion
inf3rnus asked this question in Q&A
Discussion options

You must be logged in to vote
  1. MobX don't know the relationship between multiple asynchronous actions, unless you change the promise chain to a generator function and use MobX flow to wrap it in.
  2. However, MobX flow has no business meaning, it's only a tool to automaticly wrap [async code blocks written in generators with yield keyword] into actions.
  3. In the official doc, MobX don't recommend using reaction too much: https://mobx.js.org/reactions.html#use-reactions-sparingly
  4. Your requirement is exactly what Rxjs's switchMap operator do: when source emits, all the previous subscriptions are cancelled, and new subscriptions are established.

What you described is not to "cancel actions" but rather to "cancel a series of p…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@inf3rnus
Comment options

Answer selected by kubk
Comment options

You must be logged in to vote
2 replies
@inf3rnus
Comment options

@suyingtao
Comment options

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