Uniform.TS β A modern replacement for all my web workers libraries.
Note: The project is being revived. There are no guarantees of stability yet, but new architectural ideas and sketches are in progress.
- Unified approach to working with web workers
- New architectural patterns
- Not based on any organic principles
npm install uniform.ts
# or
yarn add uniform.ts
// deno-lint-ignore-file no-explicit-any
import moduleLoader, { doTransfer, getContext, sync } from "../dist/uniform.js";
// import moduleLoader, { doTransfer, getContext, sync } from "../dist-wp/main.mjs";
// TypeScript modules aren't supported directly...
const module = (await (moduleLoader(new URL("./Worker.mjs", import.meta.url).href)?.catch?.(console.trace.bind(console)))) as any;
const ctx = getContext(module);
if (!ctx) throw new Error("Invalid context or worker...");
const transferCheck = (ab: any) => { console.log(ab); };
const hostAction = async () => {
// @ts-ignore ""
const TestClass: any = module.TestClass;
console.log(await TestClass.lab);
const tgn = (new TestClass());
await tgn?.callback?.(6);
// Get arrayBuffer from context registry
console.log(await doTransfer(ctx, "", module?.regrets));
}
// Set context extras (visible in worker)
ctx["transferCheck"] = transferCheck;
ctx["hostAction"] = hostAction;
// Synchronize
await ctx[sync];
const workerAction = (await module?.workerAction);
await hostAction();
await workerAction?.();
let ctx = {}, utils = {};
export const $importContext$ = (U) => ({ ctx, utils } = U);
export class TestClass {
constructor() {
console.log("Chips");
this.clips = 0;
}
static get lab() {
return 5;
}
callback(n = 0) {
console.log("Crispy:" + (this.clips + n));
}
}
export const regrets = new ArrayBuffer(64);
export const workerAction = async () => {
const transferCheck = await ctx?.["transferCheck"];
const bravery = new ArrayBuffer(64);
await (transferCheck?.(utils.transfer(ctx, bravery)));
console.warn(bravery);
}
We welcome your pull requests and issues!
Uniform.TS β a modern approach to working with web workers!