Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alleninstitute/vis-core",
"version": "0.0.5",
"version": "0.0.6",
"contributors": [
{
"name": "Lane Sawyer",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ export {
HEARTBEAT_RATE_MS,
} from './workers/messages';

export { WorkerPool } from './workers/worker-pool';
export { WorkerPool, type WorkerInit } from './workers/worker-pool';
12 changes: 10 additions & 2 deletions packages/core/src/workers/worker-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ type MessageValidator<T> = TypeGuardFunction<unknown, T>;

type TypeGuardFunction<T, S extends T> = (value: T) => value is S;

export type WorkerInstantiationCallback = () => Worker;

export type WorkerInit = URL | WorkerInstantiationCallback;

type MessagePromise = {
validator: MessageValidator<WorkerMessageWithId>;
resolve: PromiseResolve<WorkerMessageWithId>;
Expand All @@ -30,11 +34,15 @@ export class WorkerPool {
#timeOfPreviousHeartbeat: Map<number, number>;
#which: number;

constructor(size: number, workerModule: URL) {
constructor(size: number, workerInit: WorkerInit) {
this.#workers = new Array(size);
this.#timeOfPreviousHeartbeat = new Map();
for (let i = 0; i < size; i++) {
this.#workers[i] = new Worker(workerModule, { type: 'module' });
if (workerInit instanceof URL) {
this.#workers[i] = new Worker(workerInit, { type: 'module' });
} else {
this.#workers[i] = workerInit();
}
this.#workers[i].onmessage = (msg) => this.#handleMessage(i, msg);
this.#timeOfPreviousHeartbeat.set(i, 0);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/omezarr/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@alleninstitute/vis-omezarr",
"version": "0.0.15",
"version": "0.0.16",
"contributors": [
{
"name": "Lane Sawyer",
Expand Down
4 changes: 2 additions & 2 deletions packages/omezarr/src/zarr/cache-lower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import type { OmeZarrShapedDataset, OmeZarrMetadata } from './types';
import { type ZarrRequest, buildQuery, loadZarrArrayFileFromStore } from './loading';
import { VisZarrDataError } from '../errors';
import * as zarr from 'zarrita';
import { logger } from '@alleninstitute/vis-core';
import { logger, type WorkerInit } from '@alleninstitute/vis-core';
import { ZarrFetchStore, type CachingMultithreadedFetchStoreOptions } from './cached-loading/store';

export function decoderFactory(url: string, workerModule: URL, options?: CachingMultithreadedFetchStoreOptions) {
export function decoderFactory(url: string, workerModule: WorkerInit, options?: CachingMultithreadedFetchStoreOptions) {
const store = new ZarrFetchStore(url, workerModule, options);
const getSlice = async (
metadata: OmeZarrMetadata,
Expand Down
5 changes: 3 additions & 2 deletions packages/omezarr/src/zarr/cached-loading/store.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Cacheable, logger, PriorityCache, WorkerPool } from '@alleninstitute/vis-core';
import { type Cacheable, logger, PriorityCache, type WorkerInit, WorkerPool } from '@alleninstitute/vis-core';
import * as zarr from 'zarrita';
import { FETCH_MESSAGE_TYPE, type FetchResponseMessage, isFetchResponseMessage } from './fetch-data.interface';

Expand Down Expand Up @@ -310,8 +310,9 @@ export class CachingMultithreadedFetchStore extends zarr.FetchStore {
return this.#doFetch(key, range, workerOptions, abort);
}
}

export class ZarrFetchStore extends CachingMultithreadedFetchStore {
constructor(url: string | URL, workerModule: URL, options?: CachingMultithreadedFetchStoreOptions) {
constructor(url: string | URL, workerModule: WorkerInit, options?: CachingMultithreadedFetchStoreOptions) {
super(url, new WorkerPool(options?.numWorkers ?? DEFAULT_NUM_WORKERS, workerModule), options);
}
}