Skip to content

Advantage of flow over async/await? #3171

Answered by urugator
schontz asked this question in Q&A
Discussion options

You must be logged in to vote

Accepted answer:

#3171 (reply in thread)

Original answer:

*increment() {
    this.count++;
    yield this.incrementLater();
}

is equivalent to:

async increment() {
   runInAction(() => {
      this.count++;
   })   
   await this.incrementLater();
}

Besides mobx complaining about mutating observable outside action the practical implications are only noticable if you mutate multiple observables at a time:

async increment() {
    this.count++;
    this.foo++;
    this.bar++;
    await this.incrementLater();
}

This would result in 4 individual invocations of observers (instead of 2 if using flow).

Replies: 1 comment 8 replies

Comment options

You must be logged in to vote
8 replies
@schontz
Comment options

@urugator
Comment options

@schontz
Comment options

@schontz
Comment options

@urugator
Comment options

Answer selected by urugator
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