VTKJS cancelling reader promise

Hi All,

Apologies if this is a really basic question or betrays a lack of understanding on my part.

I have a page where vtkXMLImageDataReader is used to load some data from the web. Using a sequence like this

var reader = new vtkXMLImageDataReader.newInstance({ fetchGzip: true });
reader.onModified(renderComponent);
reader.setUrl(dataUrl).then( () => reader.loadData() );

This works fine, but I want a way to cancel the reader promise, for example, if the user clicks away from the page and the component is no longer required. I tried calling a reader.delete() method, but vtkXMLImageDataReader does not seem to have this method.

Any help would be gratefully received.

Thanks

I don’t think we have cancelable promises in vtk.js.

Also a side note. With vtk.js you should not have a need for new. The newInstance() method create a new instance of that object for you.

Thanks, good to know.

To give a bit more detail what I am doing is using the reader inside a React component. So what I need is the best practice for the componentWillUnmount method.

Any suggestions are welcome.

You can do the network part outside of vtk.js and just pass the data once available if not unmounted before that.