Skip to content

Conversation

@duartencarvalho
Copy link

No description provided.

@Touffy
Copy link
Owner

Touffy commented Jun 11, 2023

Hi Duarte.

I think it would be more in line with existing APIs (fetch, etc.) to accept a signal instead of a controller to allow external code to abort the DownloadStream. Granted, it would take slightly more code (one line, I guess).

Also… I don't mean to pry, but I'm curious about what use-case you may have for this feature ?

@duartencarvalho
Copy link
Author

Hello! I understand your point, but how can you abort the here

cancel(e) { controller.abort(e) iterator.throw?.(e) }
if you only have the signal?

I allow users to export big media projects, and they have to be able to cancel the download if they need to. Was there a way of doing this without changing the module? :)

@Touffy
Copy link
Owner

Touffy commented Jun 11, 2023

If the user is downloading from a stream, usually they can use their browser's UI to cancel the download and that will implicitly call cancel on the DownloadStream and abort its fetch requests. You don't have to provide a button in your own UI for that. You know, just use the browser's good old download manager.

But if you really need the external abort, the way to do it is to listen for the abort event on the external signal and react by calling abort on the internal controller :

externalSignal.addEventListener("abort", function (e) { controller.abort(this.reason) })

It may take a little more code if you want to take into account the possibility that the external signal is already aborted when the DownloadStream starts. Again, that may seem like a weird thing to happen, but fetch does it — if you give it an aborted signal, it will reject immediately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants