# VTKJS cancelling reader promise

**URL:** https://discourse.vtk.org/t/vtkjs-cancelling-reader-promise/7342
**Category:** Web
**Created:** [December 6, 2021, 9:19am UTC](https://discourse.vtk.org/t/vtkjs-cancelling-reader-promise/7342 "2021-12-06T09:19:49Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![kit](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/9fc29f/32.png) [@kit](https://discourse.vtk.org/u/kit)
#### Post date: [December 6, 2021, 9:19am UTC](https://discourse.vtk.org/t/vtkjs-cancelling-reader-promise/7342/1 "2021-12-06T09:19:49Z")

</div>

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

```auto
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

---

<div class="post-metadata">

### Author: ![Sebastien\_Jourdain](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sebastien_jourdain/32/100_2.png) [@Sebastien\_Jourdain](https://discourse.vtk.org/u/Sebastien_Jourdain)
#### Post date: [December 6, 2021, 3:50pm UTC](https://discourse.vtk.org/t/vtkjs-cancelling-reader-promise/7342/2 "2021-12-06T15:50:35Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![kit](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/9fc29f/32.png) [@kit](https://discourse.vtk.org/u/kit)
#### Post date: [December 9, 2021, 7:21pm UTC](https://discourse.vtk.org/t/vtkjs-cancelling-reader-promise/7342/3 "2021-12-09T19:21:45Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Sebastien\_Jourdain](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sebastien_jourdain/32/100_2.png) [@Sebastien\_Jourdain](https://discourse.vtk.org/u/Sebastien_Jourdain)
#### Post date: [December 9, 2021, 7:32pm UTC](https://discourse.vtk.org/t/vtkjs-cancelling-reader-promise/7342/4 "2021-12-09T19:32:20Z")

</div>

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