Spaces:
Paused
Paused
Download node_modules/@plotly/mapbox-gl/src/util/worker_pool.js from Leon4gr45/UserSyncFrontend: direct link, hf CLI and curl.
- Browser
- Download file 1.51 kB
-
https://huggingface.co/spaces/Leon4gr45/UserSyncFrontend/resolve/main/node_modules/%40plotly/mapbox-gl/src/util/worker_pool.js
- Command line
-
hf download hf://spaces/Leon4gr45/UserSyncFrontend/node_modules/@plotly/mapbox-gl/src/util/worker_pool.js
-
curl -L -o worker_pool.js https://huggingface.co/spaces/Leon4gr45/UserSyncFrontend/resolve/main/node_modules/%40plotly/mapbox-gl/src/util/worker_pool.js
1.51 kB
| // @flow | |
| import WebWorker from './web_worker'; | |
| import type {WorkerInterface} from './web_worker'; | |
| import browser from './browser'; | |
| export const PRELOAD_POOL_ID = 'mapboxgl_preloaded_worker_pool'; | |
| /** | |
| * Constructs a worker pool. | |
| * @private | |
| */ | |
| export default class WorkerPool { | |
| static workerCount: number; | |
| active: {[_: number | string]: boolean}; | |
| workers: Array<WorkerInterface>; | |
| constructor() { | |
| this.active = {}; | |
| } | |
| acquire(mapId: number | string): Array<WorkerInterface> { | |
| if (!this.workers) { | |
| // Lazily look up the value of mapboxgl.workerCount so that | |
| // client code has had a chance to set it. | |
| this.workers = []; | |
| while (this.workers.length < WorkerPool.workerCount) { | |
| this.workers.push(new WebWorker()); | |
| } | |
| } | |
| this.active[mapId] = true; | |
| return this.workers.slice(); | |
| } | |
| release(mapId: number | string) { | |
| delete this.active[mapId]; | |
| if (this.numActive() === 0) { | |
| this.workers.forEach((w) => { | |
| w.terminate(); | |
| }); | |
| this.workers = (null: any); | |
| } | |
| } | |
| isPreloaded(): boolean { | |
| return !!this.active[PRELOAD_POOL_ID]; | |
| } | |
| numActive(): number { | |
| return Object.keys(this.active).length; | |
| } | |
| } | |
| const availableLogicalProcessors = Math.floor(browser.hardwareConcurrency / 2); | |
| WorkerPool.workerCount = Math.max(Math.min(availableLogicalProcessors, 6), 1); | |