Skip to content

Commit

Permalink
problem: vite can't dynamically import workers
Browse files Browse the repository at this point in the history
  • Loading branch information
gsovereignty committed Apr 18, 2024
1 parent a30bc75 commit fa9fb24
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/lib/snort_workers/main.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import { writable } from 'svelte/store';
import { Command, FrontendData } from './types';

import WorkerVite from "./master_worker?worker"

let worker:Worker;

export let FrontendDataStore = writable(new FrontendData())

// const workerScript = import.meta.env.DEV
// ? new URL("./", import.meta.url)
// : new WorkerVite();

export async function Init() {
const w = await import('./master_worker.ts?worker');
worker = new w.default();
//const w = await import('./master_worker.ts?worker');
const worker = new WorkerVite()
//worker = new w.default();
worker.onmessage = (x: MessageEvent<FrontendData>) => {
FrontendDataStore.update((current) => {
current = x.data;
return current;
});
};;
worker.postMessage(new Command("start", ""));
worker.postMessage(new Command("start")); //todo add pubkey
}

export function UpdatePubkey(pubkey:string) {
Expand Down
7 changes: 5 additions & 2 deletions src/lib/snort_workers/master_worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { derived, writable } from 'svelte/store';
import { Command, FrontendData, WorkerData } from './types';
import { followsFromKind3, getNostrEvent, tagSplits } from './utils';
import type { NostrEvent } from '@nostr-dev-kit/ndk';
import WorkerVite from "./live_subs?worker"

let workerData = new WorkerData();
let workerDataStore = writable(workerData);
Expand Down Expand Up @@ -149,8 +150,9 @@ async function PermaSub(pubkeys: string[]) {
if (permaSub) {
permaSub.terminate();
}
const w = await import('./live_subs.ts?worker');
permaSub = new w.default();
//const w = await import('./live_subs.ts?worker');
//permaSub = new w.default();
permaSub = new WorkerVite()
permaSub.onmessage = (x: MessageEvent<Map<string, NostrEvent>>) => {
workerDataStore.update(current=>{
current.events = new Map([...x.data, ...current.events])
Expand Down Expand Up @@ -237,3 +239,4 @@ async function PermaSub(pubkeys: string[]) {
}
}

export default{}

0 comments on commit fa9fb24

Please sign in to comment.