diff --git a/package.json b/package.json index a0a9d75..83ace80 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "build": "npx rimraf dist && npm run html && npm run docs && npm run build:types && npm run build:webpack && npm run build:site", "build:webpack": "NODE_ENV=production webpack", "build:types": "tsc", - "build:site": "cp dist/*function-plot.js site/js", + "build:site": "cp dist/*function-plot.js site/js && cp dist/*function-plot.js.map site/js", "start": "webpack-dev-server", "docs": "typedoc --excludeExternals --externalPattern \"**/node_modules/**\" --out site/docs src/index.ts", "test": "NODE_OPTIONS='--experimental-vm-modules' jest", diff --git a/src/index.ts b/src/index.ts index c1838d3..27d57a0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,7 +15,9 @@ registerGraphType('scatter', scatter) registerGraphType('text', text) // Web workers initializer. -function withWebWorkers(nWorkers = 8) { +function withWebWorkers(nWorkers = 8, publicPath = window.location.href) { + // @ts-ignore + global.__webpack_public_path__ = publicPath globals.workerPool = new IntervalWorkerPool(nWorkers) } diff --git a/src/samplers/interval.ts b/src/samplers/interval.ts index 7648971..4e28556 100644 --- a/src/samplers/interval.ts +++ b/src/samplers/interval.ts @@ -51,19 +51,14 @@ async function asyncInterval1d({ ) } - const samples: IntervalSamplerResultGroup = [] - let allWorkersDone: Array - try { - allWorkersDone = await Promise.all(promises) - } catch (err) { - // This run was invalidated by a new run. - ;(samples as any).scaledDx = 0 - return [samples] - } - // Transfer the typed array back to the main thread. + const allWorkersDone = await Promise.all(promises) + + // Transfer the typed arrays back to the main thread. for (let i = 0; i < allWorkersDone.length; i += 1) { interval2dTypedArrayGroups[i] = new Float32Array(allWorkersDone[i]) } + + const samples: IntervalSamplerResultGroup = [] for (let i = 0; i < interval2dTypedArrayGroups.length; i += 1) { const group = interval2dTypedArrayGroups[i] for (let j = 0; j < group.length; j += 4) { diff --git a/src/samplers/interval_worker_pool.ts b/src/samplers/interval_worker_pool.ts index 5cd7c04..f232dbb 100644 --- a/src/samplers/interval_worker_pool.ts +++ b/src/samplers/interval_worker_pool.ts @@ -78,7 +78,9 @@ class IntervalWorkerPool { while (this.hasWork()) { const task = this.tasks.shift() if (!task.valid) { - this.rejects[task.nTask](new Error('This task is no longer valid')) + // This task is no longer valid (because there's a newer task) + // resolve with the input value. + this.resolves[task.nTask](task.interval2d.buffer) continue } const idleWorker = this.idleWorkers.shift()