Skip to content

Commit

Permalink
Use AbortController to try abort chunks onDestroy()
Browse files Browse the repository at this point in the history
  • Loading branch information
will-moore committed Oct 15, 2024
1 parent c03dbd2 commit c847454
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 13 deletions.
10 changes: 8 additions & 2 deletions ome2024-ngff-challenge/src/Thumbnail.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script>
import { onMount } from "svelte";
import { onMount, onDestroy } from "svelte";
import * as zarr from "zarrita";
import { slice } from "@zarrita/indexing";
import {
Expand Down Expand Up @@ -27,6 +27,8 @@
let height = width / thumbAspectRatio;
let showSpinner = true;
const controller = new AbortController();
async function loadThumbnail() {
let paths = attrs.multiscales[0].datasets.map((d) => d.path);
let axes = attrs.multiscales[0].axes.map((a) => a.name);
Expand Down Expand Up @@ -86,7 +88,7 @@
}
return 0;
});
return zarr.get(arr, slices);
return zarr.get(arr, slices, { opts: { signal: controller.signal } });
});
let ndChunks = await Promise.all(promises);
Expand Down Expand Up @@ -114,6 +116,10 @@
onMount(() => {
loadThumbnail();
});
onDestroy(() => {
controller.abort();
});
</script>
<!-- Need a wrapper to show spinner -->
Expand Down
17 changes: 8 additions & 9 deletions ome2024-ngff-challenge/src/ZarrListItem.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { filesizeformat } from "./util";
import { loadMultiscales } from "./tableStore";
import Thumbnail from "./Thumbnail.svelte";
import { onDestroy } from "svelte";
export let rowData;
export let textFilter;
Expand All @@ -13,6 +14,7 @@
let thumbDatasetIndex;
let thumbAspectRatio = 1;
const controller = new AbortController();
// If we have shape info
if (rowData.size_x && rowData.size_y) {
let longestSide = Math.max(rowData.size_x, rowData.size_y);
Expand All @@ -36,11 +38,15 @@
if (rowData.series0 !== undefined) {
zarrUrl += "/" + rowData.series0;
}
let img = await loadMultiscales(zarrUrl);
let img = await loadMultiscales(zarrUrl, controller.signal);
imgAttrs = img[0];
imgUrl = img[1];
plateAttrs = img[2]; // optional
});
onDestroy(() => {
// Doesn't seem to abort fetching of chunks
controller.abort();
});
$: description = (textFilter != "" && rowData.description?.includes(textFilter)) ? rowData.description : "";
Expand Down Expand Up @@ -97,6 +103,7 @@
flex-direction: row;
align-items: start;
gap: 10px;
background-color: var(--background-color);
}
table {
margin-left: 10px;
Expand All @@ -106,12 +113,4 @@
font-size: 80%;
line-height: normal;
}
.link_logo {
width: 24px;
height: 24px;
visibility: hidden;
}
.zarr-list-item:hover .link_logo {
visibility: visible;
}
</style>
1 change: 1 addition & 0 deletions ome2024-ngff-challenge/src/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ body {
color: #333;
position: absolute;
inset: 0;
--background-color: white;
--border-color: lightgrey;
--light-background: #eee;
--selected-background: #eee;
Expand Down
4 changes: 2 additions & 2 deletions ome2024-ngff-challenge/src/tableStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { organismStore, imagingModalityStore } from "./ontologyStore";
import { range, getRandomInt } from "./util.js";
const BATCH_SIZE = 5;

export async function loadMultiscales(url) {
export async function loadMultiscales(url, signal) {
// return the json data that includes multiscales
let zarrData = await fetch(`${url}/zarr.json`)
let zarrData = await fetch(`${url}/zarr.json`, { signal })
.then((response) => {
if (response.status === 404) {
throw new Error(`${url}/zarr.json not found`);
Expand Down

0 comments on commit c847454

Please sign in to comment.