Allows pausing and resuming matching operations (e.g., during user adjustments).
Maintains a queue of waiters that are notified when pause is lifted.
Source
letmanualPauseActive = false;
/** * Queue of resolve functions waiting for pause to be lifted. * @source */ letpauseWaiters: Array<() =>void> = [];
/** * Check if manual pause is currently active. * @returns True if matching is manually paused. * @source */ exportfunctionisManualPauseActive(): boolean { returnmanualPauseActive; }
/** * Resolve all pending pause waiters and clear the queue. * @source */ functionresolvePauseWaiters(): void { // Capture current waiters before clearing to avoid issues if new waiters are added during resolution constcurrentWaiters = pauseWaiters; pauseWaiters = []; for (constresolveofcurrentWaiters) { resolve(); } }
/** * Wait until manual pause is lifted. Returns immediately if not paused. * @returns Promise that resolves when pause is lifted or immediately if not paused. * @source */ exportasyncfunctionwaitWhileManuallyPaused(): Promise<void> { while (manualPauseActive) { awaitnewPromise<void>((resolve) =>pauseWaiters.push(resolve)); } }
/** * Set manual matching pause state and notify waiters when resuming. * Dispatches a custom event for UI synchronization. * @parampaused - Whether to pause (true) or resume (false) matching. * @source */ exportfunctionsetManualMatchingPause(paused: boolean): void { if (paused) { manualPauseActive = true; } elseif (manualPauseActive) { manualPauseActive = false; resolvePauseWaiters(); }
Manual pause functionality for rate limiting.
Allows pausing and resuming matching operations (e.g., during user adjustments). Maintains a queue of waiters that are notified when pause is lifted.
Source