integration layer; merge work on indicators from forks with existing ingestion pipeline

This commit is contained in:
Roberto Treviño Cervantes
2026-10-23 00:00:14 -06:00
parent b0608fdc70
commit d9245fe9b7
194 changed files with 21773 additions and 848 deletions
@@ -0,0 +1,35 @@
import { Injectable } from '@angular/core';
import { defer, finalize, Observable, Subscription } from 'rxjs';
// Shared by availability and KPI data; figure requests retain their existing lifecycle.
@Injectable({ providedIn: 'root' })
export class IndicadoresRequests {
private active = 0;
private readonly queue: (() => void)[] = [];
run<T>(request: () => Observable<T>): Observable<T> {
return new Observable<T>(subscriber => {
let started = false;
let subscription: Subscription | undefined;
const start = () => {
started = true;
this.active++;
subscription = defer(request).pipe(finalize(() => {
this.active--;
this.drain();
})).subscribe(subscriber);
};
if (this.active < 4) start();
else this.queue.push(start);
return () => {
if (!started) {
const index = this.queue.indexOf(start);
if (index >= 0) this.queue.splice(index, 1);
}
subscription?.unsubscribe();
};
});
}
private drain() {
while (this.active < 4 && this.queue.length) this.queue.shift()!();
}
}