Skip to content

XRequest 是否可以支持打断 #458

Open
@ZYLBless

Description

需求动机

使用 XRequest 发起请求后,希望能主动终止请求。目前是否能通过自定义 fetch 的方式实现?

const controllerRef = useRef<AbortController | null>(null);
controllerRef.current = new AbortController();
const { signal } = controllerRef.current;

const exampleRequest = () => {
  const mockFetch = fetch(BASE_URL + PATH, {signal});
  return XRequest({
      baseURL: BASE_URL + PATH,
      model: MODEL,
      fetch: mockFetch,
  })
};

const onRequest = await exampleRequest.create(
     ...
};

<Sender
  onSubmit={(nextContent) => {
      onRequest(nextContent);
  }}
  onCancel={() => controllerRef.current?.abort();}
/>

提议的 API 是什么样的?

controllerRef.current = new AbortController();
const { signal } = controllerRef.current;
XRequest({
      baseURL: BASE_URL + PATH,
      model: MODEL,
      signal: signal
  })

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions