2.4.8-a • Published 7 months ago

@bz0/binter2 v2.4.8-a

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

❤️‍🔥 BInter v2.4 (Civet Edition) ❤️‍🔥

Former InterWork or InterWork2, IW2. Renamed due of branding.

🗺 Motivation 🗺

I decided to write my own library inspired by Comlink or Coincident. Based mainly on the latest and modern EcmaScript standards. Last year's first version, released sometime in 2021 or 2022, was a big bump in the road. So I decided to rewrite the project... I decided that those libraries have some serious drawbacks, especially related to proxying. There may be other problems as well. I decided not to ask these offices to guide me to the right solution.

🐆 What a Civet edition? 🐆

It means, based on Civet-compatible (ES-mode) language. There also not so big bug-fixes, mostly syntax reworking. Planned also custom operators for lazy ops, or function context. In general, not so many difference from v2.3.

👷 Purpose 👷

IW2 - is multi-purpose WebWorker and WebSocket library.

You can

  • Copy typed arrays between workers or sockets.
  • Use proxy of DOM from Web (Worker or Socket).
  • Use in image processing (by OffscreenCanvas).
  • Transfer data between main and worker.
  • Use for WebAssembly (uses sync ops).
  • Use SharedArrayBuffer with Atomic.
  • Acceleration or offload some hard tasks.
  • Using remote function or class (i.e. module) as is.

⭐ Features ⭐

(Generated by Chad)

  • Ease of use: IW2 offers a simple and intuitive API for creating, managing, and communicating with web workers.
  • Data transmission: The library makes it easy to transmit complex objects and data between the main thread and workers.
  • Remote function calls: IW2 allows for calling functions that execute in web workers by simply passing the function name and parameters.
  • Message handling: The library provides a mechanism for conveniently handling and responding to messages received from web workers.
  • Worker pooling: IW2 supports worker pooling, allowing for efficient utilization of available resources and management of worker creation and destruction.
  • High performance: IW2 is optimized for data exchange between the main thread and web workers, providing fast message transmission and processing.
  • Scalability: IW2 supports working with multiple web workers, allowing efficient resource utilization and distribution of tasks among them.
  • Support for various message types: IW2 can handle different types of data, including text, numbers, objects, and arrays. This makes the library flexible and versatile for different use cases.
  • Compatibility: IW2 is compatible with modern browsers that support web workers, such as Chrome, Firefox, and Safari.
  • Fault tolerance: IW2 ensures reliable message transmission between the main thread and workers, handling possible errors and exceptions.

🚉 Platform support 🚉

Frontend

  • Chrome/Edge/Chromium (experimental)
  • Firefox (tested on Nightly)

Backend

  • Deno (experimental)
  • Bun.js (tested, no support ES6 mode)
  • Node.js (planned, delayed)

📚 Dependency 📚

🪁 Example 🪁

Wrapper examples

Browser (fastify)

<script type="importmap">
    {
        "imports": {
            ".": ".",
            "cbor-x/": "/cbor-x/",
            "cbor-x": "/cbor-x/index.js",
            "@petamoriken/": "/@petamoriken/",
            "@petamoriken/float16": "/@petamoriken/float16/browser/float16.mjs",
            "src/": "/src/",
            "test/": "/test/",
            "deps/": "/deps/",
            "BTyped2/": "/BTyped2/"
        }
    }
</script>
import IW from "src/index.mjs";
import { main } from "../worker/main.mjs";

//import { Worker, isMainThread, parentPort, workerData, } from 'node:worker_threads'

const $R = location?.href ?? Deno?.cwd?.();

const importMap = {
    imports: {
        ".": `${$R}.`,
        "cbor-x/": `${$R}cbor-x/`,
        "cbor-x": `${$R}cbor-x/index.js`,
        "@petamoriken/": `${$R}@petamoriken/`,
        "@petamoriken/float16": `${$R}@petamoriken/float16/browser/float16.mjs`,
        "src/": `${$R}src/`,
        "test/": `${$R}test/`,
        "deps/": `${$R}deps/`,
        "BTyped2/": `${$R}BTyped2/`,
    },
};

// get worker internal library
const worker = new Worker(
    IW.WrapWorkerURL(
        new URL("../worker/worker.mjs", import.meta.url).href,
        importMap,
    ),
    {
        //type: "module",
        deno: { permissions: "inherit" },
        importMap: import.meta.importMap,
    },
);

//
main(worker);

Deno

import IW from "src/index.mjs";
import { main } from "../worker/main.mjs";

// get worker internal library
const worker = new Worker(
    IW.WrapWorkerURL(new URL("../worker/worker.mjs", import.meta.url).href),
    {
        type: "module",
        deno: { permissions: "inherit" },
        importMap: import.meta.importMap,
    },
);

//
main(worker);

🤚 ShadowRealm... ✋

We waiting support for ShadowRealm in browsers!

ShadowRealm already available on Canary Chrome, Chromium daily and Firefox Nightly...

📦 Install 📦

Currently, available ways:

  • git submodule add https://github.com/BlazerNEO/BInter2.git deps/InterWork2
  • git clone https://github.com/BlazerNEO/BInter2.git --recursive
  • npm install (for test)

📦 Projects 📦

  • 🪖 BTyped2 🪖 - library for encoders and decoders, also for animations. "Required!"
  • ❤️‍🔥 BInter2 ❤️‍🔥 - next-gen pure JS web worker library.
  • 🥀 BQuery 🥀 - JQuery alternative, competitor, wrapper, library.

🗿 Standby... 🗿

  • 🖼 BImage 🖼 - unified image formats library.
  • 📚 BlazerNEO 📚 - an official repository website.
2.4.8-a

7 months ago

2.4.7-a

7 months ago

2.4.6-a

7 months ago

2.4.5-a

7 months ago

2.4.4-a

7 months ago

2.4.1-a

7 months ago

2.4.3-a

7 months ago

2.4.2-a

7 months ago

2.4.0-a

7 months ago

2.3.15-a

7 months ago

2.3.14-a

7 months ago

2.3.13-a

7 months ago

2.3.12-a

7 months ago

2.3.11-a

7 months ago

2.3.10-a

7 months ago

2.3.9-a

7 months ago

2.3.8-a

7 months ago

2.3.7-a

7 months ago

2.3.6-a

7 months ago

2.3.5-a

7 months ago

2.3.4-a

7 months ago

2.3.3-a

7 months ago

2.3.2-a

7 months ago

2.3.1-a

7 months ago

2.3.0-a

7 months ago

2.2.6-a

7 months ago

2.2.5-a

7 months ago

2.2.4-a

7 months ago

2.2.3-a

7 months ago

2.2.2-a

7 months ago

2.2.1-a

7 months ago

2.2.0-a

7 months ago