DEV Community

Discussion on: Async + Await refactor, which do you like best?

Collapse
 
avalander profile image
Avalander • Edited

I don't think that async/await is a bad thing, but I like that Promises force you to think what parts of your code depend on which asynchronous data and to organise it accordingly. Async/await allows you to write asynchronous code like it is synchronous and I have mixed feelings about this.

It's worth mentioning that I don't use either, I usually use Fluture because it doesn't automagically catch all and every error in the rejection branch, which you can't achieve with async/await or Promises. But the Fluture API is quite similar to a Promise and I kind of like it.

Also, notice that if the goal is to remove indentation, there is no reason why the last then of the example on the left can't be rewritten as

.then(response => {
    this.updateEventValues()
    return this.Alert.success('Se ha actualizado el evento')
)
.then(() => this.clearEventAndClose())

Which has the additional benefit that if you need to catch any rejection, you only need to do it once.

Collapse
 
ben profile image
Ben Halpern

I agree with this logic