Skip to content

Commit

Permalink
fix(io): do not terminate global worker
Browse files Browse the repository at this point in the history
  • Loading branch information
floryst committed Jul 29, 2024
1 parent 869d2fb commit a9b5d96
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/io/readWriteImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import {
writeImage as writeImageItk,
} from '@itk-wasm/image-io';
import { vtiReader, vtiWriter } from '@/src/io/vtk/async';
import { getWorker } from '@/src/io/itk/worker';

export const readImage = async (file: File) => {
if (file.name.endsWith('.vti'))
return (await vtiReader(file)) as vtkImageData;

const { image, webWorker } = await readImageItk(file);
webWorker.terminate();
const { image } = await readImageItk(file, { webWorker: getWorker() });
return vtkITKHelper.convertItkToVtkImage(image);
};

Expand All @@ -34,7 +34,8 @@ export const writeImage = async (format: string, image: vtkImageData) => {
}
}

const result = await writeImageItk(itkImage, `image.${format}`);
result.webWorker?.terminate();
const result = await writeImageItk(itkImage, `image.${format}`, {
webWorker: getWorker(),
});
return result.serializedImage.data;
};
6 changes: 4 additions & 2 deletions src/io/readers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { convertItkToVtkImage } from '@kitware/vtk.js/Common/DataModel/ITKHelper';
import { readImage, extensionToImageIo } from '@itk-wasm/image-io';
import { getWorker } from '@/src/io/itk/worker';
import { FileReaderMap } from '.';

import { stlReader, vtiReader, vtpReader } from './vtk/async';
Expand All @@ -14,8 +15,9 @@ export const ITK_IMAGE_MIME_TYPES = Array.from(
);

async function itkReader(file: File) {
const { image, webWorker } = await readImage(file);
webWorker.terminate();
const { image } = await readImage(file, {
webWorker: getWorker(),
});
return convertItkToVtkImage(image);
}

Expand Down

0 comments on commit a9b5d96

Please sign in to comment.