POC to use AbortSignal to cancel an ongoing download#296
POC to use AbortSignal to cancel an ongoing download#296mycodedstuff wants to merge 1 commit intogram-js:masterfrom
Conversation
054fc97 to
9c64115
Compare
9c64115 to
8434fbc
Compare
|
hmm I'm not sure. downloadMedia and downloadFile use iterDownload for await (const chunk of iterDownload(client, {
file: inputLocation,
requestSize: partSize,
dcId: dcId,
msgData: msgData,
})) {
await writer.write(chunk);
if (progressCallback) {
await progressCallback(downloaded, fileSize || 0);
}
downloaded += chunk.length;
}so it's preferable if when the users wants to abort/stop/resume that they use iterDownload since they can stop it whenever they want |
Yeah that's true. I didn't consider using the callback for that purpose. At the end it's your call. We can close this PR. But this discussion can atleast help others figure things out. |
|
I'm open to having a pause/stop/resume functionality We could still use the controller thing and make it a downloadController instead of abort. If you want you can do it or I can build on top of this PR. |
Currently gramjs doesn't provide any way to cancel/abort an ongoing download.
I implemented a simple system which uses AbortController and AbortSignal to break the loop which fetches the chunks.
This is a POC so that we can discuss if there are any caveats in this idea. This can be simillary implemented for all other kinds of downloads (document, video, profile picture, etc).
Example:
This raises an
USER_ABORTEDerror from downloadMedia which can be handled by the client.Note: This implementation is only checked with Nodejs, I haven't tested it in browsers.