Skip to content

Commit

Permalink
feat(offscreen): fix offscreen init types
Browse files Browse the repository at this point in the history
  • Loading branch information
DeltaZN committed Dec 3, 2023
1 parent 3ac3354 commit 48d44b4
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/chart/canvas/offscreen/init-offscreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import { isOffscreenCanvasModel } from './canvas-offscreen-wrapper';
import { OffscreenWorker } from './offscreen-worker';

export const isOffscreenWorkerAvailable = typeof Worker !== 'undefined';
const OffscreenWorkerClass = isOffscreenWorkerAvailable
? wrap<typeof OffscreenWorker>(new Worker(new URL('./offscreen-worker.js', import.meta.url)))
: // ? wrap<typeof OffscreenWorker>(new Worker(new URL('http://localhost:3000/offscreen-worker.js')))
class {};
const OffscreenWorkerClass =
isOffscreenWorkerAvailable &&
wrap<typeof OffscreenWorker>(new Worker(new URL('./offscreen-worker.js', import.meta.url)));

// create global worker instance, so every chart will use the same worker
export let offscreenWorker: Remote<OffscreenWorker>;
Expand All @@ -16,8 +15,11 @@ let canvasesIdxOffset = 0;

export const initOffscreenWorker = async (canvases: CanvasModel[]): Promise<Remote<OffscreenWorker>> => {
if (offscreenWorker === undefined) {
// @ts-ignore
offscreenWorker = await new OffscreenWorkerClass();
if (typeof OffscreenWorkerClass === 'function') {
offscreenWorker = await new OffscreenWorkerClass();
} else {
return Promise.reject('Offscreen worker is not available.');
}
}
const startOffset = canvasesIdxOffset;
canvasesIdxOffset += 10;
Expand Down

0 comments on commit 48d44b4

Please sign in to comment.