How to use abortcontroller-polyfill - 9 common examples

To help you get started, we’ve selected a few abortcontroller-polyfill 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 parcel-bundler / parcel / packages / core / core / src / Parcel.js View on Github external
async startNextBuild() {
    this.#watchAbortController = new AbortController();

    try {
      this.#watchEvents.emit({
        buildEvent: await this.build({
          signal: this.#watchAbortController.signal,
        }),
      });
    } catch (err) {
      // Ignore BuildAbortErrors and only emit critical errors.
      if (!(err instanceof BuildAbortError)) {
        throw err;
      }
    }
  }
github waitingsong / rxxfetch / packages / rxxfetch / src / lib / util.ts View on Github external
function parseAbortController(options: ArgsRequestInitCombined): ArgsRequestInitCombined {
  const { args, requestInit } = options

  /* istanbul ignore else */
  // eslint-disable-next-line @typescript-eslint/unbound-method
  if (! args.abortController || ! args.abortController.signal || typeof args.abortController.abort !== 'function') {
    args.abortController = typeof AbortController === 'function'
      ? new AbortController()
      : new _AbortController()
  }
  /* istanbul ignore else */
  if (args.abortController) {
    requestInit.signal = args.abortController.signal
  }

  return { args, requestInit }
}
github waitingsong / rxxfetch / packages / rxxfetch / src / lib / config.ts View on Github external
keepRedirectCookies: false,
  method: 'GET',
  processData: true,
  timeout: null,

  cache: 'default',
  credentials: 'same-origin',
  mode: 'cors',
  redirect: 'follow',
  referrer: 'client',
}

// for node.js
if (typeof window === 'undefined') {
  if (typeof fetch !== 'function') {
    initialRxRequestInit.fetchModule = abortableFetch(_fetch).fetch
  }

  if (typeof Headers !== 'function') {
    initialRxRequestInit.headersInitClass = _Headers
  }
}


export const httpErrorMsgPrefix = 'Fetch error status:'
github elbywan / wretch / test / node / wretch.spec.ts View on Github external
it("should abort a request", function (done) {
        let count = 0

        const handleError = error => {
            expect(error.name).toBe("AbortError")
            count++
        }

        const controller = new AbortController()
        wretch(`${_URL}/longResult`)
            .signal(controller)
            .get()
            .res()
            .catch(handleError)
        controller.abort()

        const [c, w] = wretch(`${_URL}/longResult`).get().controller()
        w.res().catch(handleError)
        c.abort()

        wretch(`${_URL}/longResult`)
            .get()
            .setTimeout(100)
            .onAbort(handleError)
            .res()
github Azure / ms-rest-js / test / defaultHttpClientTests.ts View on Github external
function getAbortController(): AbortController {
  let controller: AbortController;
  if (typeof AbortController === "function") {
    controller = new AbortController();
  } else {
    const AbortControllerPonyfill = require("abortcontroller-polyfill/dist/cjs-ponyfill").AbortController;
    controller = new AbortControllerPonyfill();
  }
  return controller;
}
github Azure / autorest.typescript / test / xml / xmlTests.ts View on Github external
function getAbortController(): AbortController {
  let controller: AbortController;
  if (typeof AbortController === "function") {
    controller = new AbortController();
  } else {
    const AbortControllerPonyfill = require("abortcontroller-polyfill/dist/cjs-ponyfill").AbortController;
    controller = new AbortControllerPonyfill();
  }
  return controller;
}
github elbywan / wretch / test / node / wretch.spec.ts View on Github external
function (url, opts) {
        performance.mark(url + " - begin")
        const { fetch } = abortableFetch(nodeFetch) as any
        return fetch(url, opts).then(_ => {
            performance.mark(url + " - end")
            const measure = () => performance.measure(_.url, url + " - begin", url + " - end")
            performance.clearMarks(url + " - begin")
            if(timeout)
                setTimeout(measure, timeout)
            else
                measure()
            return _
        })
    }
github chainpoint / chainpoint-client-js / lib / utils / network.js View on Github external
nodes.map(async node => {
      try {
        isValidNodeURI(node)
        let controller, signal, timeoutId
        if (AbortController) {
          controller = new AbortController()
          signal = controller.signal
          timeoutId = setTimeout(() => controller.abort(), timeout)
        }
        await fetch(node, { timeout, method: 'GET', signal })

        clearTimeout(timeoutId)
        return node
      } catch (e) {
        failures.push(node)
      }
    })
  )
github chainpoint / chainpoint-client-js / lib / utils / network.js View on Github external
* See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
 * helper functions related to interacting with chainpoint network objects
 * such as nodes and cores
 */

import { resolveTxt } from 'dns'
import { parse } from 'url'
import { promisify } from 'util'
import { isInteger, isFunction, isEmpty, slice, map, shuffle, filter, first, isString } from 'lodash'
import { isURL, isIP } from 'validator'
const { AbortController, abortableFetch } = require('abortcontroller-polyfill/dist/cjs-ponyfill')
const { fetch } = abortableFetch(require('node-fetch'))

import getConfig from '../config'
import { DNS_CORE_DISCOVERY_ADDR } from '../constants'
import { testArrayArg } from './helpers'

let config = getConfig()

/**
 * Check if valid Core URI
 *
 * @param {string} coreURI - The Core URI to test for validity
 * @returns {bool} true if coreURI is a valid Core URI, otherwise false
 */
export function isValidCoreURI(coreURI) {
  if (isEmpty(coreURI) || !isString(coreURI)) return false

abortcontroller-polyfill

Polyfill/ponyfill for the AbortController DOM API + optional patching of fetch (stub that calls catch, doesn't actually abort request).

MIT
Latest version published 11 days ago

Package Health Score

85 / 100
Full package analysis

Similar packages