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
fix(useFetch): fix incorrect chainCallbacks
behavior
#2231
Conversation
Promise.all() is parallel, and to ensure that the order of execution is predictable, it should probably look like this. function chainCallbacks<T = any>(...callbacks: (((ctx: T) => void | Partial<T> | Promise<void | Partial<T>>) | undefined)[]) {
return async (ctx: T) => {
await callbacks.reduce((prevCallback, callback)=>{
return prevCallback.then(async ()=>{
if (callback)
ctx = { ...ctx, ...(await callback(ctx)) }
})
}, Promise.resolve())
return ctx
}
} |
Oh, you're right! And it makes sense that executing callback in order. Really appreciate for your review! |
Thanks for your contribution! Would you mind add a test cases for it ? |
Sure |
1ac8e26
to
c5530e3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seem okay to me
Description
fixes #2225, #1310
Additional context
Like @imaverickk metioned in #2225, there's another solution: usePromise.all()
. I'm not sure which one is betterWhat is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).