Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have any good way to implement multi promise control like Async? #1070

Closed
hank7444 opened this issue Nov 25, 2015 · 4 comments
Closed

Have any good way to implement multi promise control like Async? #1070

hank7444 opened this issue Nov 25, 2015 · 4 comments

Comments

@hank7444
Copy link

example1, I have 3 apis need to call, if they all resolve, return success and get me all data which return by those apis. If one of them are rejected, return failure to me.

example2, I have 2 apis need to call, if one of them resolve, return success and get me data.
If all of them are rejected, return failure to me.

Have any possible do such like these sophisticated async control on redux?

I have already used apiMiddleware, but it only use on 1 ajax call..

@just-boris
Copy link
Contributor

It is not a Redux thing. You can do it with native promise

example 1

Promise.all([callAPI1(), callAPI2(), callAPI3()]).then(onSucces, onFailure)

example 2

Promise.race([callAPI1(), callAPI2(), callAPI3()]).then(onSucces, onFailure)

then you can wrap it code in action using https://github.com/gaearon/redux-thunk or https://github.com/acdlite/redux-promise and it will work

Look at the docs on MDN if you want more information

@hank7444
Copy link
Author

@just-boris thx! I will try it~

@itsmepetrov
Copy link

Also, for combining async actions you can use redux-combine-actions.

@gaearon
Copy link
Contributor

gaearon commented Nov 25, 2015

Yes, we suggest using middleware like redux-thunk or redux-promise for this. You can then use Promise.all and other Promise composition functions. Note that you need to include a polyfill for Promises to use them safely—for example, you may use the polyfill that ships with Babel by importing babel-core/polyfill.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants