Skip to content

How to handle Download cancellations with Service Worker #64

Answered by Touffy
JulianBerger asked this question in Q&A
Discussion options

You must be logged in to vote

When the Service Worker's client cancels the download, that should cancel the Zip stream from the Worker's point of view.

As you noticed, the output stream cancellation should now throw an error up the chain of async generators that makes up downloadZip (I haven't actually tested it yet).

So at the source, if you passed an (async) iterable to downloadZip, you can catch that error in there and trigger the AbortSignal for any ongoing fetch. Here is a simplified example :

// assuming that `urls` is an array of URLs for the files
async function* source() {
  const downloadController = new AbortController()
  const { signal } = downloadController

  // of course you should not generally start …

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@Touffy
Comment options

@Touffy
Comment options

@JulianBerger
Comment options

@pixide
Comment options

@Touffy
Comment options

Answer selected by Touffy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
3 participants
Converted from issue

This discussion was converted from issue #62 on May 14, 2023 22:03.