@just-every/ensemble
Version:
LLM provider abstraction layer with unified streaming interface
50 lines • 1.53 kB
JavaScript
import { EventEmitter } from 'events';
class PauseControllerImpl extends EventEmitter {
_isPaused = false;
isPaused() {
return this._isPaused;
}
pause() {
if (!this._isPaused) {
this._isPaused = true;
this.emit('paused');
console.log('[PauseController] System paused');
}
}
resume() {
if (this._isPaused) {
this._isPaused = false;
this.emit('resumed');
console.log('[PauseController] System resumed');
}
}
async waitWhilePaused(checkInterval = 100, abortSignal) {
while (this._isPaused && !abortSignal?.aborted) {
await new Promise(resolve => setTimeout(resolve, checkInterval));
}
if (abortSignal?.aborted) {
const { PauseAbortError } = await import('../types/errors.js');
throw new PauseAbortError();
}
}
}
let pauseControllerInstance = null;
export function getPauseController() {
if (!pauseControllerInstance) {
pauseControllerInstance = new PauseControllerImpl();
}
return pauseControllerInstance;
}
export function isPaused() {
return getPauseController().isPaused();
}
export function pause() {
getPauseController().pause();
}
export function resume() {
getPauseController().resume();
}
export async function waitWhilePaused(checkInterval, abortSignal) {
return getPauseController().waitWhilePaused(checkInterval, abortSignal);
}
//# sourceMappingURL=pause_controller.js.map