mirror of
https://git.um-react.app/um/um-react.git
synced 2025-11-28 11:33:02 +00:00
feat: get web worker mechanism working (pass file around)
This commit is contained in:
@@ -1 +1,18 @@
|
||||
import { ConcurrentQueue } from '../util/ConcurrentQueue';
|
||||
import { WorkerClientBus } from '../util/WorkerEventBus';
|
||||
import { DECRYPTION_WORKER_ACTION_NAME } from './constants';
|
||||
|
||||
// TODO: Worker pool?
|
||||
export const workerClient = new Worker(new URL('./worker', import.meta.url), { type: 'module' });
|
||||
|
||||
class DecryptionQueue extends ConcurrentQueue<{ id: string; blobURI: string }> {
|
||||
constructor(private workerClientBus: WorkerClientBus, maxQueue?: number) {
|
||||
super(maxQueue);
|
||||
}
|
||||
|
||||
async handler(item: { id: string; blobURI: string }): Promise<void> {
|
||||
return this.workerClientBus.request(DECRYPTION_WORKER_ACTION_NAME.DECRYPT, item.blobURI);
|
||||
}
|
||||
}
|
||||
|
||||
export const decryptionQueue = new DecryptionQueue(new WorkerClientBus(workerClient));
|
||||
|
||||
3
src/decrypt-worker/constants.ts
Normal file
3
src/decrypt-worker/constants.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export enum DECRYPTION_WORKER_ACTION_NAME {
|
||||
DECRYPT = 'DECRYPT',
|
||||
}
|
||||
@@ -1,3 +1,12 @@
|
||||
onmessage = (e) => {
|
||||
console.log(e.data);
|
||||
};
|
||||
import { WorkerServerBus } from '../util/WorkerEventBus';
|
||||
import { DECRYPTION_WORKER_ACTION_NAME } from './constants';
|
||||
|
||||
const bus = new WorkerServerBus();
|
||||
onmessage = bus.onmessage;
|
||||
|
||||
bus.addEventHandler(DECRYPTION_WORKER_ACTION_NAME.DECRYPT, async (blobURI) => {
|
||||
const blob = await fetch(blobURI).then((r) => r.arrayBuffer());
|
||||
// TODO: Implement decryptor for blob received here.
|
||||
console.log(blob);
|
||||
return { hello: true };
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user