Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | 8x 8x 8x 8x 1x 2x 2x | import { defaultBrowserWorkerCount, normalizeBrowserWorkerCount } from '@be-music/player-browser/compute';
export const WORKER_COUNT_STORAGE_KEY = 'be-music.worker-count';
export interface WorkerSettingsStorage {
getItem(key: string): string | null;
setItem(key: string, value: string): void;
}
/** Blocked storage and invalid values use half the browser-reported logical CPU count. */
export function readWorkerCount(storage: WorkerSettingsStorage | undefined, cores: number | undefined): number {
try {
const value = storage?.getItem(WORKER_COUNT_STORAGE_KEY);
return value === null || value === undefined
? defaultBrowserWorkerCount(cores)
: normalizeBrowserWorkerCount(Number(value), cores);
} catch {
return defaultBrowserWorkerCount(cores);
}
}
export function storeWorkerCount(storage: WorkerSettingsStorage | undefined, count: number): void {
try {
storage?.setItem(WORKER_COUNT_STORAGE_KEY, String(count));
} catch {
/* Private browsing can disable storage. */
}
}
|