chqcose

Results 6 comments of chqcose

+1,如果基础现有功能,前端实现的话,现在有没有啥好的方式推荐呀

看了一下,有很多类似执行取消或者监听取消的诉求 #2371 #1826 #1634 #1498 通过AbortController可以比较友好的实现,像自定义的Promise也可以通过它的事件方式实现中止 ``` const controller = new AbortController(); const signal = controller.signal; new Promise((resolve, reject) => { setTimeout(resolve, 3000); signal.addEventListener("abort", () => { console.log("Request aborted"); reject();...

> 如果要解决这个问题,是不是直接在 onBefore 里支持取消 promise 的执行就好了,比如 onBefore 里如果返回的是 false,onRequest 就不执行了。 onBefore是service还没有开始执行的时候吧,我的场景是service已经开始执行,但还没结束(fetch请求已发出没收到响应)

``` typescript import { useRef } from 'react'; import { useRequest } from 'ahooks'; type IService = (signal: AbortSignal, ...args: TParams) => Promise; type IOptions = Parameters[1]; type IPlugins =...

供参考 ``` import React, { useState } from 'react'; import { Button, ButtonProps } from 'antd'; interface ActionButtonProps extends ButtonProps { onClick?(e: React.MouseEvent): Promise | any; } function isThenable(thing?: PromiseLike):...