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;
}
}
}
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;
}
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)
}
})
)