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

useRequest 同时执行多次 runAsync, 只执行了最后一个 then 函数 #2078

Open
yi-man opened this issue Feb 24, 2023 · 12 comments
Open
Labels
feature New feature or request

Comments

@yi-man
Copy link

yi-man commented Feb 24, 2023

现象

同时执行多次 runAsync, 只执行了最后一个 then 函数

截屏2023-02-24 16 51 55

可能有问题的代码

应该是由下方代码引起

if (currentCount !== this.count) {
      // prevent run.then when request is canceled
      return new Promise(() => {});
    }

demo

https://codesandbox.io/s/demo-for-ahooks-forked-5yk8lg?file=/src/App.js

@liuyib
Copy link
Collaborator

liuyib commented Feb 25, 2023

@crazylxr 见哥 看下这个是符合预期的吗?我测试的 React v16-v18 都存在这个问题

@crazylxr
Copy link
Collaborator

符合预期的哈。

@liuyib
Copy link
Collaborator

liuyib commented Feb 26, 2023

@yi-man 这是符合预期的行为,issue 关了哈,还有其他疑问的话我再重开 issue

@liuyib liuyib closed this as completed Feb 26, 2023
@zilianghm
Copy link

我说怎么循环里 runAsync 请求一直得不到正确的数据,这是坑,人为制造的坑,一个请求 api,需要你做防抖节流吗?然后文档还不写清楚这个点。

@crazylxr
Copy link
Collaborator

crazylxr commented May 8, 2023

我说怎么循环里 runAsync 请求一直得不到正确的数据,这是坑,人为制造的坑,一个请求 api,需要你做防抖节流吗?然后文档还不写清楚这个点。

这不是防抖节流,这属于竟态请求。文档里是有写的,https://ahooks.js.org/zh-CN/hooks/use-request/basic#%E5%8F%96%E6%B6%88%E5%93%8D%E5%BA%94

请把文档好好看完再说话

@liuyib
Copy link
Collaborator

liuyib commented May 8, 2023

然后文档还不写清楚这个点

image

觉着文档不够清晰,可以提个 PR 帮忙改进~ @zilianghm

@94zn
Copy link

94zn commented Sep 21, 2023

希望能有参数能修改这个机制,我今天也遇到了

@skyfore
Copy link

skyfore commented Jan 11, 2024

希望能够有参数控制不启用竞态,比如只是想用 useRequest 包装 loading 以及 error 的状态,发现多次调用只回调了一次,也会很疑惑,甚至建议是可以抛错出来的,都会比直接把上个请求 padding 更合理
@liuyib

@liuyib liuyib reopened this Jan 11, 2024
@liuyib liuyib added the feature New feature or request label Jan 11, 2024
@soulcm
Copy link

soulcm commented Mar 8, 2024

没有什么参数控制吗,有时不想要这个竞态

@nianyi778
Copy link

我其实希望后续的请求不要发起,也就是说保留第一个。

@nianyi778
Copy link

我其实希望后续的请求不要发起,只要保留第一个。

如果可以配置规则就好了

@crazylxr
Copy link
Collaborator

这个问题下个大版本会重点考虑

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

No branches or pull requests

8 participants