@wevu/web-apis
Version:
Web API polyfills and global installers for mini-program runtimes
29 lines (28 loc) • 910 B
JavaScript
import { t as RequestGlobalsEventTarget } from "./shared-BB491DgN.mjs";
//#region src/abort.ts
function createAbortError(reason) {
if (reason instanceof Error) return reason;
if (typeof DOMException === "function") return new DOMException("The operation was aborted.", "AbortError");
const error = /* @__PURE__ */ new Error("The operation was aborted.");
error.name = "AbortError";
return error;
}
var AbortSignalPolyfill = class extends RequestGlobalsEventTarget {
aborted = false;
reason;
onabort = null;
throwIfAborted() {
if (this.aborted) throw createAbortError(this.reason);
}
};
var AbortControllerPolyfill = class {
signal = new AbortSignalPolyfill();
abort(reason) {
if (this.signal.aborted) return;
this.signal.aborted = true;
this.signal.reason = reason;
this.signal.dispatchEvent({ type: "abort" });
}
};
//#endregion
export { AbortControllerPolyfill, AbortSignalPolyfill };