🔧 Fixing comlink
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import * as React from "react";
|
||||
import _ from "lodash";
|
||||
import { connect } from "react-redux";
|
||||
import main from "../workers/extractCovers.worker";
|
||||
interface IProps {
|
||||
matches: unknown;
|
||||
}
|
||||
@@ -26,8 +25,10 @@ class Import extends React.Component<IProps, IState> {
|
||||
}
|
||||
|
||||
public async startFolderWalk() {
|
||||
const foo = await main();
|
||||
console.log("as", foo);
|
||||
const worker = new Worker(
|
||||
new URL("../workers/extractCovers.worker", import.meta.url),
|
||||
);
|
||||
console.log(worker);
|
||||
}
|
||||
public render() {
|
||||
return (
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
import strategy from "clooney";
|
||||
import { expose } from "comlink";
|
||||
|
||||
class Actor {
|
||||
timeoutThing() {
|
||||
return new Promise(resolve => setTimeout(_ => resolve('ohai'), 1000));
|
||||
}
|
||||
}
|
||||
const foo = (value: string) => {
|
||||
return "rishi" + " " + value;
|
||||
};
|
||||
|
||||
const instance = await strategy.spawn(Actor);
|
||||
alert(await instance.timeoutThing()); // Will alert() after 1 second
|
||||
const bar = (value: number) => {
|
||||
return value + 10;
|
||||
};
|
||||
|
||||
const exported = {
|
||||
foo,
|
||||
bar,
|
||||
};
|
||||
|
||||
export type Worker = typeof exported;
|
||||
expose(exported);
|
||||
|
||||
13
src/client/workers/tsconfig.json
Normal file
13
src/client/workers/tsconfig.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"strict": true,
|
||||
"target": "esnext",
|
||||
"module": "esnext",
|
||||
"lib": ["webworker", "esnext"],
|
||||
"moduleResolution": "node",
|
||||
"noUnusedLocals": true,
|
||||
"sourceMap": true,
|
||||
"allowJs": false,
|
||||
"baseUrl": "."
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user