58ca4e68db
- Go backend API with full CRUD for all modules (CRM, Sales, Finance, HR, Legal, Marketing, Support, Purchase, Inventory, Projects, Automation, Analytics) - Rust analytics service with parallel report generation - C runtime with POSIX shared memory IPC - PostgreSQL schema with 30+ tables, full migrations - Redis cache, sessions, pub/sub - Kafka event streaming with Zookeeper - WebSocket hub for real-time updates - Automation engine with cron jobs, workflows, event triggers - JWT authentication, multi-tenant from start - Docker Compose with all services - Nginx reverse proxy with rate limiting - Integration tests passing - Feature gap analysis against Fortnox/Odoo/Visma Refs: BOC-001
58 lines
1.4 KiB
JavaScript
58 lines
1.4 KiB
JavaScript
import CanceledError from '../cancel/CanceledError.js';
|
|
import AxiosError from '../core/AxiosError.js';
|
|
import utils from '../utils.js';
|
|
|
|
const composeSignals = (signals, timeout) => {
|
|
signals = signals ? signals.filter(Boolean) : [];
|
|
|
|
if (!timeout && !signals.length) {
|
|
return;
|
|
}
|
|
|
|
const controller = new AbortController();
|
|
|
|
let aborted = false;
|
|
|
|
const onabort = function (reason) {
|
|
if (!aborted) {
|
|
aborted = true;
|
|
unsubscribe();
|
|
const err = reason instanceof Error ? reason : this.reason;
|
|
controller.abort(
|
|
err instanceof AxiosError
|
|
? err
|
|
: new CanceledError(err instanceof Error ? err.message : err)
|
|
);
|
|
}
|
|
};
|
|
|
|
let timer =
|
|
timeout &&
|
|
setTimeout(() => {
|
|
timer = null;
|
|
onabort(new AxiosError(`timeout of ${timeout}ms exceeded`, AxiosError.ETIMEDOUT));
|
|
}, timeout);
|
|
|
|
const unsubscribe = () => {
|
|
if (!signals) { return; }
|
|
timer && clearTimeout(timer);
|
|
timer = null;
|
|
signals.forEach((signal) => {
|
|
signal.unsubscribe
|
|
? signal.unsubscribe(onabort)
|
|
: signal.removeEventListener('abort', onabort);
|
|
});
|
|
signals = null;
|
|
};
|
|
|
|
signals.forEach((signal) => signal.addEventListener('abort', onabort, { once: true }));
|
|
|
|
const { signal } = controller;
|
|
|
|
signal.unsubscribe = () => utils.asap(unsubscribe);
|
|
|
|
return signal;
|
|
};
|
|
|
|
export default composeSignals;
|