Skip to content

u2re-space/uniform.ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🏬 Uniform.TS 🏬

Uniform.TS β€” A modern replacement for all my web workers libraries.

GitHub Repo GitHub stars License Last Commit npm version Build Status Coverage Status Issues PRs Welcome


Key Links


🚧 Project Status

Note: The project is being revived. There are no guarantees of stability yet, but new architectural ideas and sketches are in progress.


✨ Key Concepts

  • Unified approach to working with web workers
  • New architectural patterns
  • Not based on any organic principles

πŸ“¦ Installation

npm install uniform.ts
# or
yarn add uniform.ts

πŸ§‘β€πŸ’» Usage Example

Host Code

// 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?.();

ES Module for Worker Context

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);
}

πŸ“š Documentation


🀝 Contributing

We welcome your pull requests and issues!


πŸ“ License

MIT License


Uniform.TS β€” a modern approach to working with web workers!

About

🏬 Replacement of all my web workers libraries. 🏬

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •