Skip to content

Commit

Permalink
Merge pull request #1105 from InsightSoftwareConsortium/fix-create-we…
Browse files Browse the repository at this point in the history
…b-worker-null

fix(create-web-worker): allow undefined workerUrl
  • Loading branch information
thewtex authored Apr 10, 2024
2 parents 607eb83 + cdd95a4 commit e489ad6
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import RunPipelineOptions from './run-pipeline-options'
async function createWebWorker (pipelineWorkerUrl?: string | null, queryParams?: RunPipelineOptions['pipelineQueryParams']): Promise<Worker> {
const workerUrl = pipelineWorkerUrl
let worker = null
if (workerUrl === null) {
if (workerUrl == null) {
// Use the version built with the bundler
//
// Bundlers, e.g. WebPack, Vite, Rollup, see these paths at build time
worker = new Worker(new URL('./web-workers/itk-wasm-pipeline.worker.js', import.meta.url), { type: 'module' })
} else {
if ((workerUrl as string).startsWith('http')) {
const response = await axios.get((workerUrl as string), { responseType: 'blob', params: queryParams })
if (workerUrl.startsWith('http')) {
const response = await axios.get(workerUrl, { responseType: 'blob', params: queryParams })
const workerObjectUrl = URL.createObjectURL(response.data as Blob)
worker = new Worker(workerObjectUrl, { type: 'module' })
} else {
worker = new Worker((workerUrl as string), { type: 'module' })
worker = new Worker(workerUrl, { type: 'module' })
}
}

Expand Down

0 comments on commit e489ad6

Please sign in to comment.