Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
}
}
}
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 }
}
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:'
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()
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;
}
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;
}
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 _
})
}
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)
}
})
)
* 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