Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancel active operation? #9

Closed
danwexler opened this issue Jan 12, 2021 · 4 comments
Closed

Cancel active operation? #9

danwexler opened this issue Jan 12, 2021 · 4 comments
Labels
enhancement New feature or request

Comments

@danwexler
Copy link
Contributor

Upscale on larger images can take awhile. Might be nice to be able to cancel active upscales. Perhaps via the return value of the progress() callback?

@danwexler
Copy link
Contributor Author

danwexler commented Jan 15, 2021

I've implemented this in my tree for testing using the following patch (works in both Browser Worker and node):

diff --git a/node_modules/upscaler/dist/upscale.js b/node_modules/upscaler/dist/upscale.js
index 77d57fc..a9c0733 100644
--- a/node_modules/upscaler/dist/upscale.js
+++ b/node_modules/upscaler/dist/upscale.js
@@ -138,7 +138,7 @@ exports.predict = (model, pixels, modelDefinition, { progress, patchSize, paddin
                 yield tf.nextFrame();
                 if (progress) {
                     const index = row * columns + col + 1;
-                    progress(index / total);
+                    if (progress(index / total)) throw new Error('Upscale canceled')
                 }
                 const slicedPrediction = prediction.slice([0, sliceOrigin[0] * scale, sliceOrigin[1] * scale], [-1, sliceSize[0] * scale, sliceSize[1] * scale]);
                 yield tf.nextFrame();

@thekevinscott
Copy link
Owner

Being able to cancel an upscale operation is a fantastic idea.

I'm not sure I love the idea of doing it via the progress callback, though. To me, leveraging something like an abortable promise feels more intuitive, so you could do something like:

const pendingOperation = upscaler.upscale();

pendingOperation.abort();

Alternatively, fetch has a similar API, and uses AbortController to accomplish the same. A bit more verbose of an approach.

I also think having a top-level abortAll (or cancelAll?) would be useful, so you don't need to manually keep track of all ongoing operations.

Thoughts?

@stale
Copy link

stale bot commented Apr 22, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Apr 22, 2021
@stale stale bot closed this as completed Apr 30, 2021
@thekevinscott thekevinscott reopened this Nov 9, 2021
@thekevinscott thekevinscott added enhancement New feature or request and removed wontfix This will not be worked on labels Nov 9, 2021
@thekevinscott thekevinscott mentioned this issue Mar 3, 2022
@thekevinscott
Copy link
Owner

This has been implemented in:

#235

https://upscalerjs.com/#/?id=abort

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants