Skip to content

Commit

Permalink
Implement cancel example
Browse files Browse the repository at this point in the history
  • Loading branch information
thekevinscott committed Mar 5, 2022
1 parent 07470a9 commit 9853bc8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
Binary file removed examples/cancel/flower-256.png
Binary file not shown.
4 changes: 2 additions & 2 deletions examples/cancel/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<body>
<h1>Cancel Example</h1>
<p>An example demonstrating how to cancel an inflight request of the upscale method.</p>
<p>Click the upscale button to upscale the photo, and then click cancel to cancel it.</p>
<p>Click the upscale button (it is purposefully slow) to upscale the photo, and then click cancel to cancel it.</p>
<button id="upscale">Upscale</button>
<button id="cancel">Cancel</button>
<p id="info"></p>
Expand All @@ -50,7 +50,7 @@ <h1>Cancel Example</h1>
</thead>
<tbody>
<tr><td>
<img src="/flower-256.png" id="flower" />
<img src="/flower.png" id="flower" />
</td>
<td>
<div id="target">
Expand Down
8 changes: 4 additions & 4 deletions examples/cancel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ const upscaler = new Upscaler();
upscale.onclick = () => {
info.innerText = 'Upscaling...';
const start = new Date().getTime();
let rate;
let rate = 0;
upscaler.upscale(img, {
patchSize: 4,
patchSize: 16,
padding: 4,
signal: abortController.signal,
progress: (inProgressRate) => {
Expand All @@ -27,13 +27,13 @@ upscale.onclick = () => {
const ms = new Date().getTime() - start;
info.innerText = `Upscaled in ${ms} ms`;
}).catch(err => {
console.log(err);
console.log('The AbortError:', err);
info.innerText = `Canceled at ${rate}%`;

});
};

cancel.onclick = () => {
console.log('canceled');
abortController.abort();
abortController = new AbortController();
}
7 changes: 2 additions & 5 deletions examples/cancel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
"description": "Demonstrates how to cancel an inflight upscale request.",
"main": "index.js",
"scripts": {
"start": "cross-env NODE_ENV=development parcel index.html --no-hmr --open"
"copy": "rm -rf dist && mkdir dist && cp index.html dist && cp flower.png dist",
"start": "yarn copy && esbuild index.js --servedir=dist --outdir=dist --bundle --loader:.png=dataurl"
},
"author": "Kevin Scott",
"license": "MIT",
"devDependencies": {
"cross-env": "^7.0.2",
"parcel": "1.12.3"
},
"dependencies": {
"@tensorflow/tfjs": "^3.13.0",
"upscaler": "0.11.0"
Expand Down

0 comments on commit 9853bc8

Please sign in to comment.