How to use @aws-sdk/abort-controller - 3 common examples

To help you get started, we’ve selected a few @aws-sdk/abort-controller examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aws / aws-sdk-js-v3 / packages / node-http-handler / src / node-http2-handler.spec.ts View on Github external
it("will close request on session when aborted", async () => {
      await nodeH2Handler.handle(new HttpRequest(getMockReqOptions()), {});

      // @ts-ignore: access private property
      const session: ClientHttp2Session = nodeH2Handler.connectionPool.get(
        `${protocol}//${hostname}:${port}`
      );
      const requestSpy = jest.spyOn(session, "request");

      const abortController = new AbortController();
      // Delay response so that onabort is called earlier
      setTimeout(() => {
        abortController.abort();
      }, 0);
      mockH2Server.on(
        "request",
        async () =>
          new Promise(resolve => {
            setTimeout(() => {
              resolve(createResponseFunction(mockResponse));
            }, 1000);
          })
      );

      await expect(
        nodeH2Handler.handle(new HttpRequest(getMockReqOptions()), {
github aws / aws-sdk-js-v3 / packages / fetch-http-handler / src / fetch-http-handler.spec.ts View on Github external
it("can be aborted before fetch completes", async () => {
    const abortController = new AbortController();

    const mockFetch = jest.fn(() => {
      return new Promise((resolve, reject) => {});
    });
    (global as any).fetch = mockFetch;

    setTimeout(() => {
      abortController.abort();
    }, 100);
    const fetchHttpHandler = new FetchHttpHandler();

    await expect(
      fetchHttpHandler.handle({} as any, {
        abortSignal: abortController.signal
      })
    ).rejects.toHaveProperty("name", "AbortError");
github aws / aws-sdk-js-v3 / packages / node-http-handler / src / node-http-handler.spec.ts View on Github external
createResponseFunction(mockResponse)
      );
      let httpRequest: http.ClientRequest;
      let reqAbortSpy: any;
      const spy = jest.spyOn(https, "request").mockImplementationOnce(() => {
        let calls = spy.mock.calls;
        let currentIndex = calls.length - 1;
        httpRequest = https.request(
          calls[currentIndex][0],
          calls[currentIndex][1]
        );
        reqAbortSpy = jest.spyOn(httpRequest, "abort");
        return httpRequest;
      });
      const nodeHttpHandler = new NodeHttpHandler();
      const abortController = new AbortController();

      setTimeout(() => {
        abortController.abort();
      }, 0);

      await expect(
        nodeHttpHandler.handle(
          new HttpRequest({
            hostname: "localhost",
            method: "GET",
            port: (mockHttpsServer.address() as AddressInfo).port,
            protocol: "https:",
            path: "/",
            headers: {}
          }),
          {

@aws-sdk/abort-controller

A simple abort controller library

Apache-2.0
Latest version published 10 months ago

Package Health Score

72 / 100
Full package analysis

Popular @aws-sdk/abort-controller functions