How to cancel file loading async request

Hi I use three.TextureLoader().loadAsync() and I would like to ask, how to cancel asynch texture loading (I have virtual tour with combination of sliced panorama photos, meshes, 3dscans and so on… which are loaded on demand) and when user switch between places not actual loading requests are still arriving.

For now I solve this like:

ew three.TextureLoader().loadAsync(pathToLoad).then((texture: three.Texture) => {
       if (panorama.is_previewed) {
       }

But I would like to know if there is some more cultivated solution for this. Because in clear fetch() I know how to cancel it but I’m not sure if texture loaded interface has something like this.

1 Like

Aborting file loading requests is currently not possible. More information in the following issue and the related PR:

2 Likes

Does anyone have a sample of overriding textureloader functions to deal with an abort controller?

The circumstance is: You have a heavy application (say a world map) and you start loading an area (which might take 5 seconds to completely fill in) but the user teleports to a different area and expects loading to be 5 seconds, not 10. The previous loading areas for the old area have not yet finished.

This would be great to add to three.js, and it’s not difficult to add it. F.e. load and loadAsync could accept a signal, f.e.

textureLoader.loadAsync(pathToLoad, {signal: abortController.signal})

// later, before it finishes loading
abortController.abort()

Until then, you have to manually fetch the data yourself:

const blob = fetch(url, {signal}).then(r => r.blob())

// ... pass the data to a Texture/etc manually ...

You can also ask AIs how to modify FileLoader or Load to use an AbortController, and you’ll find it is relatively simple. Someone just needs to make a PR.