Skip to main content

Cancel Example

Demonstrates how to cancel an inflight upscale request.

Open in Stackblitz.

Cancelling requests

The mechanism for cancelling inflight requests leverages the AbortSignal object.

To cancel a request, create an instance of an AbortController, and then cancel it.

import Upscaler from 'upscaler'
import imagePath from '/path/to/image.png'

const upscaler = new Upscaler()
const abortController = new AbortController()
upcaler.upscale(imagePath, {
signal: abortController.signal,
}).catch(abortError => {
console.log('I have aborted!', abortError)

// at some later point in time ...


When abort is triggered during an upscale request, an AbortError is thrown. (AbortError is exported from the core UpscalerJS package.)

Cancelling all requests

UpscalerJS provides a convenience method for cancelling all inflight requests at once:


Calling this will cancel all inflight requests (and each will emit an AbortError).

This method can be convenient, particularly if only one upscale request is ever active at a time.