misterbl / star-wars-directory

1 stars 0 forks source link

If an error prevents from completion, break the execution sooner #3

Open qborreda opened 5 years ago

qborreda commented 5 years ago

https://github.com/misterbl/star-wars-directory/blob/a760df28e6efb05ceae6a46bf4b4ed9e9e345d12/src/actions/thunks/searchFilmsAndPeople.ts#L18

While you could have used a Promise.all for fetching these two API endpoints, your reasoning separates code by concepts. First, API calls, then error checking. When you are using async/await thou, the code is stuck on the calls until getting the response or the errors, but in this code piece, you are executing both calls and waiting for the first to finish to start the next, and then checking errors.

A better approach would have been Promise.all, or even, check for errors right after each call. There is no need for a second call to the API if there was an error in the first one, right? Unless, you had a separated state per category, and used setFatalError with the error and the category.

qborreda commented 5 years ago

Also #2 applies here

misterbl commented 5 years ago

@qborreda In the new implementation of sagas, I have used yield all()