UNPKG

@contentstack/cli-cm-clone

Version:
59 lines (58 loc) 1.7 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.CustomAbortSignal = exports.CustomAbortController = void 0; const events_1 = require("events"); /** * Custom AbortSignal implementation */ class CustomAbortSignal { constructor() { this.eventEmitter = new events_1.EventEmitter(); this.onabort = null; this.aborted = false; } toString() { return '[object CustomAbortSignal]'; } get [Symbol.toStringTag]() { return 'CustomAbortSignal'; } removeEventListener(name, handler) { this.eventEmitter.removeListener(name, handler); } addEventListener(name, handler) { this.eventEmitter.on(name, handler); } dispatchEvent(type) { const event = { type, target: this }; const handlerName = `on${type}`; // Emit event to EventEmitter listeners (for addEventListener) this.eventEmitter.emit(type, event); // Call onabort handler if it exists (for onabort property) if (typeof this[handlerName] === 'function') { this[handlerName](event); } } } exports.CustomAbortSignal = CustomAbortSignal; /** * Custom AbortController implementation */ class CustomAbortController { constructor() { this.signal = new CustomAbortSignal(); } abort() { if (this.signal.aborted) return; this.signal.aborted = true; this.signal.dispatchEvent('abort'); } toString() { return '[object CustomAbortController]'; } get [Symbol.toStringTag]() { return 'CustomAbortController'; } } exports.CustomAbortController = CustomAbortController;